Bash – Copy image from command-line to clipboard

bashclipboardcommand lineimages

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.

Best 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:

Related Question