Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a way in a bash to copy a picture to the clipboard?

For example if there is a picture mypic.png I want to have a command like clipcopy mypic.png such that I can go for example to inkscape and paste it afterwards.

share|improve this question

3 Answers 3

This python script by cheshirekow claims to do what you want.

#! /usr/bin/python
import pygtk
pygtk.require('2.0')
import gtk
import os
import sys

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()
    clipboard.set_image(image)
    clipboard.store()

copy_image(sys.argv[1]);
share|improve this answer
    
Thanks, it works to past into libreoffice, however pasting into inkscape doesn't. –  student Jan 27 '12 at 14:58

A slightly modified version of the above, using python+gtk3:

#!/usr/bin/env python

import sys
from gi.repository import Gtk, Gdk

def copy_image(f):
    image = Gtk.Image.new_from_file(f)
    clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
    if image.get_storage_type() == Gtk.ImageType.PIXBUF:
        clipboard.set_image(image.get_pixbuf())
        clipboard.store()
    else:
        print("No image has been pasted yet.")

copy_image(sys.argv[1]);

Pasting into gimp, inkscape, libreoffice works OK here.

share|improve this answer

You can use CopyQ for this. From the website:

Clipboard manager with advanced features

  • CopyQ is clipboard manager with searchable and editable history.
  • Supports Linux and Windows.
  • Experimental support for OS X 10.9+.
  • Store text, HTML, images and any other custom format.
  • Advanced command-line interface and scripting.

To copy an image (you need to indicate the MIME type):

copyq write image/png - < file.png && copyq select 0

To copy a data file (you need to indicate the MIME type):

copyq write application/pdf - < file.pdf && copyq select 0

Check their wiki for more documentation and usage examples.

See also:

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.