0

so I can open a .png file in emacs, copy the content to clipboard so I can paste it to browser for example.

0

1 Answer 1

2

If you have a buffer visiting an image file, you can mark the whole buffer (M-x mark-whole-buffer), copy it to the clipboard (M-x clipboard-kill-ring-save) and then you can do whatever you want with the contents of that clipboard.

E.g. you can create a new buffer, paste the contents of the clipboard into it (M-x clipboard-yank), and save the buffer to a file. You should now have a file identical to the original.

The only problem (which Emacs cannot solve) is what the other application will do with the contents of the clipboard. In the example above, the other application was Emacs itself and everything worked. But other applications are not always so well-behaved - e.g. you might try xsel -b -o > foo.jpg to save the contents of the clipboard to another file. However, xsel seems to mangle NUL bytes (presumably, it only handles textual data - and there are probably more problems than just the NUL bytes), so that the resulting file is deemed corrupted by the JPEG libraries. There might be a more intelligent program than xsel, but YMMV. However, as mentioned, this is NOT an Emacs problem. You have to get the other application fixed.

1
  • Thanks for pointing out the clipboard-* functions, good additions to the normal kill/yank. as you pointed it out, it works inside of emacs, but not with other applications, for example, if I paste to GitHub or here, it is not recognised as image but strong like �PNG IHDxxxxxxx. Commented May 9, 2023 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.