Skip to main content
1 of 2

The above solution is great and I use it. I also added an additional function for when I don't want to display the images inline in the text, which creates scrolling issues.

(use-package url)
(defun display-online-image-in-new-buffer (&optional url)
 (interactive)
 (unless url (setq url (url-get-url-at-point)))
 (unless url
  (error "Couldn't find URL."))
 (let ((buffer (url-retrieve-synchronously url))
    (image-buffer (generate-new-buffer "*Image*")))
  (unwind-protect
    (with-current-buffer buffer
     (goto-char (point-min))
     (search-forward "\n\n")
     (let ((data (buffer-substring (point) (point-max))))
      (with-current-buffer image-buffer
       (insert-image (create-image data nil t))
       ;; Split the window and switch to the image buffer
       (split-window-right)
       (other-window 1)
       (switch-to-buffer image-buffer)
       (other-window -1))))
   (kill-buffer buffer))))