Is it possible to insert images directly from the web with its url in org-mode? i.e. Can I paste something like this into emacs' buffer, so that it changes into the image of a cat in the link in image mode?


It just makes it a clickable link in my current settings.


It is possible with a little code. I would define a new link like this:

#+BEGIN_SRC emacs-lisp
 (lambda (path)
   (let ((img (expand-file-name
           (concat (md5 path) "." (file-name-extension path))
     (if (file-exists-p img)
     (find-file img)
       (url-copy-file path img)
       (find-file img)))))

When you click on it, you should get a cat in image mode. I didn't define export functions though. Also, the image is downloaded as a tempfile, which may or may not be convenient for you.

Then use it like this:

Then you can use these two functions to overlay or remove an image:

(defun image-url-overlays ()
  "Put image overlays on remote image urls."
  (loop for image-url in (org-element-map (org-element-parse-buffer) 'link
               (lambda (link)
                 (when (string= "image-url" (org-element-property :type link))
    (let* ((path (org-element-property :path image-url))
           (ov (make-overlay (org-element-property :begin image-url)
                 (org-element-property :end image-url)))
           (img (create-image (expand-file-name
                   (concat (md5 path)
      (overlay-put ov 'display img)
      (overlay-put ov 'image-url t))))

(defun image-url-clear-overlays ()
  "Reove overlays on image-urls."
  (require 'ov)
  (ov-clear 'image-url))

This downloads the image as a tempfile if it doesn't exist, and then puts an overlay on the link.

  • Writing your own code to solve a problem? That's cheating, man. Sep 3 '16 at 22:26

Not within the Org buffer itself, as far as I know.

If you export to HTML, however, links to images will be converted into images.

If the description is a file name or URL that points to an image, HTML export (see HTML export) will inline the image as a clickable button. If there is no description at all and the link points to an image, that image will be inlined into the exported HTML file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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