Copy image from clipboard to file

Is it possible to take an image from the clipboard and output it to a file (using X)?

I can do this with text easily:

$ xclip -selection c -o > file.text

But when I try the above with an image nothing is written.


The reason I want to do this is I don’t have an image editor installed, and it got me thinking whether I could do this without installing one.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can actually do this with xclip using -t option.

  1. See what targets are available:
$ xclip -selection clipboard -t TARGETS -o
TARGETS
image/png
text/html
  1. Note the image/png target; go ahead and get it:
$ xclip -selection clipboard -t image/png -o > /tmp/clipboard.png

Refer to the ICCCM Section 2.6.2 for further reading.

Note: xclip SVN revision 81 (from April 2010) or patches later required.

Method 2

xclip doesn’t work with images on my computer (svn84-4) :

$ xclip -selection clipboard -t image/png -o
Error: target image/png not available

But there is another program which take screenshot and paste it into a file, very simply : scrot :

scrot /tmp/myImage.png


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x