You can use the following rewritten function to display inline images as well as web image (exactly like the way to show inline images)in Org-mode (if your work environment is in Org-mode).
- when display inline image, it will generate a thumb file to local disk and display it. By using this, you can annotate your image as free as you can without damaging your original image.
- when display url image, it will save the image to a variable and display it without any download.
Any extension can be possible. Of course you can display the inline image but not generating the thumb file by slightly change. But I prefer the above way.
(defun org-display-inline-images (&optional include-linked refresh beg end)
"Display inline and url images.
Normally only links without a description part are inlined, because this
is how it will work for export. When INCLUDE-LINKED is set, also links
with a description part will be inlined. This
can be nice for a quick
look at those images, but it does not reflect what exported files will look
like.
When REFRESH is set, refresh existing images between BEG and END.
This will create new image displays only if necessary.
BEG and END default to the buffer boundaries."
(interactive "P")
(unless refresh
(org-remove-inline-images)
(if (fboundp 'clear-image-cache) (clear-image-cache)))
(save-excursion
(save-restriction
(widen)
(setq beg (or beg (point-min)) end (or end (point-max)))
(goto-char beg)
(let ((re (concat "\\(\\(http\\)\\|\\(\\[\\[\\(\\(file:\\)\\|\\([./~]\\)\\)\\)\\)\\([^]\n]+?"
(substring (org-image-file-name-regexp) 0 -2)
"\\)" (format "\\(\\(\\]%s\\)\\|\\)" (if include-linked "" "\\]"))))
old file ov img width point-begin point-end)
(while (re-search-forward re end t)
(setq old (get-char-property-and-overlay (match-beginning 1)
'org-image-overlay)
match (match-string-no-properties 0)
point-begin (match-beginning 0)
point-end (match-end 0))
(if (s-starts-with? "http" match)
(save-excursion
(let* ((buffer (url-retrieve-synchronously match))
(unwind-protect
(let ((data (with-current-buffer buffer
(goto-char (point-min))
(search-forward "\n\n")
(buffer-substring (point) (point-max)))))
(require 'image+)
(setq img (imagex--fit-to-size (create-image data 'jpeg t) 400 400)))))))
(setq file (expand-file-name
(concat (or (match-string 6) "") (match-string 7)))
width (if (eq (car (org-element-property :parent (org-element-at-point))) 'table) 200 400))
(when (file-exists-p file)
(let ((file-thumb (format "%s%s_thumb.png" (file-name-directory file) (file-name-base file))))
(if (file-exists-p file-thumb)
(let ((thumb-time (nth 5 (file-attributes file-thumb 'string)))
(file-time (nth 5 (file-attributes file 'string))))
(if (time-less-p thumb-time file-time)
(shell-command (format org-imagemagick-display-command
file width width file-thumb) nil nil)))
(shell-command (format org-imagemagick-display-command
file width width file-thumb) nil nil))
(if (and (car-safe old) refresh)
(image-refresh (overlay-get (cdr old) 'display))
(setq img (save-match-data (create-image file-thumb)))))))
(when img
(setq ov (make-overlay point-begin point-end))
(overlay-put ov 'display img)
(overlay-put ov 'face 'default)
(overlay-put ov 'org-image-overlay t)
(overlay-put ov 'modification-hooks
(list 'org-display-inline-remove-overlay))
(push ov org-inline-image-overlays)))))))