Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying a non PNG image to the X clipboard

Tags:

shell

xclip

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?

like image 211
Sr. Komodo Avatar asked Dec 18 '19 03:12

Sr. Komodo


1 Answers

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
like image 54
deFreitas Avatar answered Sep 21 '22 08:09

deFreitas