我查看了org-display-inline-images
源代码:它只是在调用create-image
. 目前似乎没有缩放选项。
我写了一个小变通方法。这有点小技巧,但也许你想尝试一下。作用:当 org 想要显示图像“~/cat.jpg”时,此函数使其看起来是否存在“~/catt.png”并显示它。如果找不到“~/catt.png”,就会调用 ImageMagick 的转换来创建它,如下所示:
convert ~/cat.jpg -thumbnail 300x300 ~/catt.png
如果需要,您可以自定义拇指大小、类型和名称。并且不要忘记安装 ImageMagick。
(defun org-display-inline-images (&optional include-linked refresh beg end)
"Display inline 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 "\\[\\[\\(\\(file:\\)\\|\\([./~]\\)\\)\\([^]\n]+?"
(substring (org-image-file-name-regexp) 0 -2)
"\\)\\]" (if include-linked "" "\\]")))
old file ov img)
(while (re-search-forward re end t)
(setq old (get-char-property-and-overlay (match-beginning 1)
'org-image-overlay))
(setq file (expand-file-name
(concat (or (match-string 3) "") (match-string 4))))
(when (file-exists-p file)
(let ((file-thumb (format "%s%st.png" (file-name-directory file) (file-name-base file) "t.png")))
(unless (file-exists-p file-thumb)
(shell-command (format "convert %s -thumbnail 300x300 %s"
file file-thumb)))
(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 (match-beginning 0) (match-end 0)))
(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))))))))))