'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 ?
Solution 1:[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';
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pysis |
