Copying an image to the clipboard from command line
Asked Answered
D

3

7

I am using ImageMagick to copy a portion of my screen into a temporary file (something.png). I would now like to paste the contents of this file into the clipboard directly from command line.

So far my script looks like this:

#!/bin/bash

TMPFILE=$(mktemp)
FORMAT='.PNG'
SCREENSHOT_FILE=${TMPFILE}${FORMAT}

mv "$TMPFILE" "$SCREENSHOT_FILE"
import "$SCREENSHOT_FILE"
cat "$SCREENSHOT_FILE" | parcellite
rm "$SCREENSHOT_FILE"

Parcellite works perfectly for command line copying and pasting, but I can’t get it to work with image. I reckon this is not a feature of parcellite. How could I do that then ?

Distefano answered 11/6, 2012 at 9:46 Comment(2)
superuser.com/questions/301851/…Inspire
@Inspire could you paste the contents for future readers ?Distefano
P
7

Have a look at xclip, especially at xclip-copyfile and xclip-pastefile.

  xclip -i < yourfile.png
Pervasive answered 12/6, 2012 at 13:53 Comment(0)
G
1

Like kan commented that qdii wants: http://superuser.com/questions/301851/how-to-copy-a-picture-to-clipboard-from-command-line-in-linux

What the community writes there


As found [here][1], the key to paste binary data to a file with `xclip` is to tell what [Media Types][2] you have on clipboard. For PNG you can:
xclip -selection clipboard -t image/png -o > "`date '+%Y-%m-%d_%T'`.png"

Or image/jpeg and .jpg for JPEG.

So now on my ~/Dropbox/.mybashrc I add an alias (clipboard2photo) to easly paste to image file (maybe someday we'll have it on Nautilus).


My automated solution

cat (xout) | xin -t (file --mime-type (xout) | cut -d':' -f2 | tail -c +2)

with

alias xclip 'xclip -selection clip-board';
alias xin 'xclip -in';
alias xout 'xclip -out';
Governor answered 22/5, 2022 at 16:21 Comment(0)
R
0

I am using this:

sleep 1; import /tmp/ss.png; xclip -selection clipboard -t image/png </tmp/ss.png

It uses imagemagick (import) and xclip. Make sure you have them installed.

Rabbi answered 7/12, 2023 at 13:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.