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
?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With