5

I recently saw that a variable org-display-remote-inline-images was added to Org mode. This is a huge one for technical documentation, but sadly I was not able to get it to work. I tried cache and then download value.

Workflow:

  1. Add [[https://URL-to-some-image.png]] to the document. (I tried also jpg and svg.)
  2. M-x org-toggle-inline-images

Am I missing something? I saw something with imagemagick in the diff-patch, imagemagick is installed on the system.

3
  • "Did not work" means what? You got errors? The image is blank? Something else? If you got errors, what were they?
    – NickD
    Apr 28, 2021 at 9:10
  • I would try a file link with a Tramp remote path. I'm not sure that insert-file-contents-literally (which is used with download) knows how to get files over HTTPS. Something like [[file:/scp:user@host:/path/to/foo.png]].
    – NickD
    Apr 28, 2021 at 9:24
  • Nothing happens, no errors, the link stays the link no picture appears. I'll try the file test later.
    – Jens Lange
    Apr 29, 2021 at 10:17

1 Answer 1

5

I agree with NickD in the comments above that out of the box this currently only works for Tramp remote links. Tested with recent build of Emacs 29 development.

Then I read somewhere that this does work in Doom Emacs so I went digging through its source.

Below is what I had to do to get my vanilla Emacs to show inline images from http / https URLs:

;; https://blog.tecosaur.com/tmio/2021-04-26-Welcome.html#inline-display-remote
;; on 2022-09-04 this only works for tramp remote links and not for http / https
(setq org-display-remote-inline-images 'cache)

;; we look to doom emacs for an example how to get remote images also working
;; for normal http / https links
;; 1. image data handler
(defun org-http-image-data-fn (protocol link _description)
  "Interpret LINK as an URL to an image file."
  (when (and (image-type-from-file-name link)
             (not (eq org-display-remote-inline-images 'skip)))
    (if-let (buf (url-retrieve-synchronously (concat protocol ":" link)))
        (with-current-buffer buf
          (goto-char (point-min))
          (re-search-forward "\r?\n\r?\n" nil t)
          (buffer-substring-no-properties (point) (point-max)))
      (message "Download of image \"%s\" failed" link)
      nil)))

;; 2. add this as link parameter for http and https
(org-link-set-parameters "http"  :image-data-fun #'org-http-image-data-fn)
(org-link-set-parameters "https" :image-data-fun #'org-http-image-data-fn)

;; 3. pull in org-yt which will advise ~org-display-inline-images~ how to do the extra handling
(use-package org-yt
  :quelpa (org-yt :fetcher github :repo "TobiasZawada/org-yt"))
(require 'org-yt)

See also:

Your Answer

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

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