2

跟进:Emacs org-display-inline-images

我设法按照 abo-abo 的建议显示内联图像。现在我想为所有这些设置一个固定的宽度大小。

设置 (setq org-image-actual-width 50) 不起作用。Emacs 选择了变量,但它没有对图像做任何事情。我们的想法是将它们显示为缩略图。

注意:我在 Linux 上使用 emacs 24.2。我可以使用 M x image-dired 显示拇指,但是,我想在 org 模式下显示固定大小的图像。正常图像已经可以显示。

4

2 回答 2

2

我查看了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))))))))))
于 2013-07-15T07:20:22.287 回答
2

org-image-actual-width只要你的 Emacs 是用 Imagemagick 支持构建的,它就可以工作。检查,评估(image-type-available-p 'imagemagick)。它将评估t您的 Emacs 是否支持 Imagemagick。

于 2019-07-16T12:36:17.370 回答