7

Several questions have already been answered regarding copying images to the X clipboard, and the answer is always to use xclip like so:

xclip -selection clipboard -t image/png -i image.png

This works, but only for PNG files. You might imagine that changing the -t image/png to the correct MIME type, such as image/jpg or image/jpeg for JPEG files, would easily solve the problem, but this simply does not work:

xclip -selection clipboard -t image/jpeg -i other_image.jpg

The image is copied to the clipboard, but is not recognized by other applications as an image. In my case, copying a JPEG image, Discord refuses to paste any content, while Firefox pastes it as if it was text, resulting in some high quality Unicode soup of random CJK characters.

What is the correct way to copy a non PNG image to the X clipboard using xclip?

oguz ismail
  • 1
  • 16
  • 47
  • 69
Sr. Komodo
  • 163
  • 1
  • 4
  • The command you suggested seems to output different things depending on what's on the clipboard. When copying a PNG file using `xclip` it shows only `TARGETS` and `image/png`; When copying text from the terminal it shows `TARGETS`, `MULTIPLE`, `UTF8_STRING`, and `STRING`; And when copying an image from Firefox it shows a lot of MIME types, including `image/png` and `image/jpeg` – Sr. Komodo Dec 18 '19 at 17:08
  • 1
    for me when i used jpeg file it did not work, but when i used png file, it worked – Joao Vitor Deon Nov 11 '20 at 20:19

2 Answers2

2

I think image/jpeg format is not supported by xclip based on my researches, anyway you always can hack in somewhat, below the solution I found, it will use convert to convert the image from jpeg to png and paste the result to the out stream, then pass this stream to xclip in png format so it can copy the image to the clipboard.

convert image.jpg png:- | xclip -selection clipboard -t image/png
deFreitas
  • 4,196
  • 2
  • 33
  • 43
-2
xclip -selection clipboard -t image/png < file_path.png

worked for me. But when i used jpeg files it did not work

Joao Vitor Deon
  • 117
  • 1
  • 5