Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can copy image in Gimp and paste it to OpenOffice document.

How to do it (copy or paste image) from command line?

share|improve this question
What does past "paste from clipboard from command line" mean? Probably the same but only for copy:… – Ciro Santilli 巴拿馬文件 六四事件 法轮功 Aug 13 '14 at 9:35
More general question for any file type:… – Ciro Santilli 巴拿馬文件 六四事件 法轮功 Aug 13 '14 at 11:50
up vote 3 down vote accepted

As found here, the key to paste binary data to a file with xclip is to tell what Media Types 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).

share|improve this answer

I believe the reason why Leo Alekseyev script does not work sometimes (on some systems) is explained in this answer to a similar question. Important part quoted here:

One oddity that is different from most other systems: if the program owning the selection (clipboard) goes away, so does the selection.

When i run Leo's script in python shell, it is working, as long as the shell is running. So i think the clipboard data is lost, when the script is terminated. The solution posted in the answer, is working for me:

#!/usr/bin/env python
import gtk 
import sys

count = 0
def handle_owner_change(clipboard, event):
    global count
    print 'clipboard.owner-change(%r, %r)' % (clipboard, event)
    count += 1
    if count > 1:

image = gtk.gdk.pixbuf_new_from_file(sys.argv[1])
clipboard = gtk.clipboard_get()
clipboard.connect('owner-change', handle_owner_change)

Update from _Vi: For completeness, adding the clipboard->file script:

import gtk, pygtk
import sys, os

clipboard = gtk.clipboard_get()
img = clipboard.wait_for_image()[1], "png", {})
share|improve this answer
It's a bit annoying how to have to quit it manually, but at least it works :). Thanks! – crazy2be Jun 24 '14 at 0:05

Try xclip, it reads from stdin and should allow you to do

xclip < image.jpg

to copy the image to the clipboard.


share|improve this answer
-1, I don't want "???##JFIF###..." in my document. – Vi. Jun 25 '11 at 23:46
Actually I did use this a lot, and, since about last year, it doesn't work anymore. Still looking for a solution. – Drasill Jul 8 '11 at 13:35
Doesn't work here... xclip is text only on my Ubuntu 12.04 – cmc Mar 28 '13 at 11:46

The following python/pygtk script does the job:

import gtk, pygtk
import sys, os

def copy_image(f):
    assert os.path.exists(f), "file does not exist"
    image = gtk.gdk.pixbuf_new_from_file(f)
    clipboard = gtk.clipboard_get()



To use this, sudo apt-get install python pygtk, paste the above code into a script, chmod +x to make executable, and you should be good to go.

share|improve this answer
Copied little png picture using this script. Can't paste it neither to OpenOffice nor into Gimp ("There is no image data in clipboard to paste"). Don't work. After copying actual picture in Gimp and using this script the buffer reverts to text that was before that. – Vi. Dec 15 '11 at 14:22
I just tried: wget && ./ Test.png, where is exactly what's pasted here. Pastes fine into Gimp. – Leo Alekseyev Dec 15 '11 at 14:34
Tried with Test.png. "There is no image data in clipboard to paste". Does it depend on running Gnome? How to debug this? I can successfully copy image in Gimp and paste in Openoffice, so in general copying works. – Vi. Dec 16 '11 at 14:04
E: Unable to locate package pygtk – qed Jan 4 '14 at 20:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .