2

Emacs can show inline images in different buffers, e.g. in org, elfeed, mu4e, gnus, etc. Is there a generic way to save such an image to a file?

I know some mode have specific functions do that. Most mail readers that show inline image attachments also have a way to save the attachment. But elfeed does not, as far as I know and org-mode does neither.

3
  • For Org mode, inline images are overlays on links, where the content of the overlay comes from a file. So you don't need to save anything: the file where the image is stored already exists: it was created when you first called org-toggle-inline-images or equivalent. Put your cursor on the image, do C-u C-x = and you'll be able to see the link (and therefore be able to get to the file). Whether the other programs you mention work the same way I don't know, but if they do, it should be possible to get to the file in a generic way through the display property of the overlay.
    – NickD
    Dec 12, 2023 at 7:31
  • @NickD Is this also true for images representing rendered LaTex formulas?
    – jmg
    Dec 12, 2023 at 14:07
  • If you are talking about LaTeX fragments in Org mode, the answer is yes.
    – NickD
    Dec 12, 2023 at 14:29

1 Answer 1

3

For Org mode, inline images are overlays on links, where the content of the overlay comes from a file. So you don't need to save anything: the file where the image is stored already exists: it was created when you first called org-toggle-inline-images or equivalent. Put your cursor on the image, do C-u C-x = and you'll be able to see the link (and therefore be able to get to the file). Whether the other programs you mention work the same way I don't know, but if they do, it should be possible to get to the file in a generic way through the display property of the overlay.

Assuming that all the programs you mention show inline images as overlays with a display property, you can get the file of the image with

(get-char-property pos 'display)

where pos is the buffer position of the overlay; e.g. you can move your cursor on the image and use (point) for the position.

You can learn about get-char-property in the usual way: C-h f get-char-property and get more information from the Emacs Lisp Reference manual: the section Examining text properties describes the function and refers to the Overlays section; in particular, the Overlay Properties section describes all such properties, including the display property, and the section The 'display' property describes the property in greater detail.

1
  • This is was the missing part. Thank you. To make it user friendly, I need to wrap this in a function that can save the in-memory image to some generated file system path.
    – jmg
    Dec 12, 2023 at 14:08

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.