qdii
qdii

Reputation: 12963

Copying an image to the clipboard from command line

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 ?

Upvotes: 7

Views: 7426

Answers (3)

ton
ton

Reputation: 4577

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.

Upvotes: 0

Pysis
Pysis

Reputation: 1596

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';

Upvotes: 1

dwalter
dwalter

Reputation: 7468

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

  xclip -i < yourfile.png

Upvotes: 7

Related Questions