跟进:Emacs 组织显示内联图像
我按照 abo-abo 的建议设法显示内联图像。现在我想为它们设置一个固定的宽度大小。
设置(setq org-image-actual-width 50)不起作用。 Emacs 选择了该变量,但它没有对图像执行任何操作。这个想法是将它们显示为缩略图。
注意:我在 Linux 上使用 emacs 24.2。
我可以使用 M x image-dired 显示拇指,但是,我想在组织模式下显示固定大小的图像。正常图像已经可以显示。
我看过org-display-inline-images
来源:
它只是在呼唤create-image
。目前似乎没有缩放选项。
我写了一个小解决方法。
这有点麻烦,但也许您想尝试一下。
作用:当 org 想要显示图像“~/cat.jpg”时,
这个函数可以查看“~/catt.png”是否存在并显示出来。
如果没有找到“~/catt.png”,则调用 ImageMagick 的 Convert 来创建它,如下所示:
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))))))))))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)