astrand / xclip

Command line interface to the X11 clipboard
GNU General Public License v2.0
1.03k stars 73 forks source link

Copying jpeg to clipboard doesn't fully work #110

Closed xadips closed 1 year ago

xadips commented 3 years ago

When I copy a .png file to clipboard using xclip -selection clipboard -t "$type" "$file" where $type is it's mime-type, and $file is it's filename it works perfectly.

But when I do it with a .jpg file the same way xclip -selection clipboard -t "$type" "$file" pasting it only works into some of the applications f.e gimp, but it doesn't act the same like .png with discord, messenger, etc.

Is this an xclip issue, or it's just that .jpg can't be copied the same way .png can?

shufuwa commented 2 years ago

same problem here

hackerb9 commented 1 year ago

Unfortunately, some web apps are very picky about what they will accept. For example, I've noticed the same problem pasting jpegs into Gmail. Many X clients that holds clipboard data are able to offer images in multiple formats and convert on the fly, so this usually is not a problem. Xclip doesn't do that. In fact, it currently can offer only one MIME type at a time.

This isn't pretty, but you can try something like convert foo.jpg png:- | xclip -i -sel c -t image/png


I think it would be a reasonable addition to xclip to be able to offer multiple mimetype targets simultaneously, perhaps with a way to delegate a program that can do the conversion as needed. But, I'm just a contributor. Such a major change would be something @astrand, xclip's author, would have to weigh in on. Besides the "small matter of coding", It would require a bit of planning and consideration. (E.g., are the known conversions builtin or specified in a config file? Or must the user specify them every time from the command line arguments?)

awalgarg commented 1 year ago

I've found a "workaround" which is to set the target to image/png even if the file is a JPEG. This works well enough to paste the image correctly in both Firefox and Chromium as well as electron based apps, at least as of this writing.

I don't think the problem here is with xclip or the X server. The problem is not even with the websites. I've filed bug reports against firefox and chromium describing this along with sample code to reproduce the issue:

  1. Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1825959
  2. Chromium: https://bugs.chromium.org/p/chromium/issues/detail?id=1430187
xadips commented 1 year ago

Closing as this is not an issue with xclip, hoping this gets fixed in the browsers.