配置emacs显示固定宽度的内联图像 [英] Configuring emacs for showing fixed width inline images

查看:151
本文介绍了配置emacs显示固定宽度的内联图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

跟进: Emacs org-display-inline-images

我设法显示内容上的图像。现在我想为所有这些设置一个固定的宽度大小。

I managed to show inline images following abo-abo's advice. Now I want to set a fixed width size for all of them.

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

Setting (setq org-image-actual-width 50) didn't work. Emacs picked the variable, but it isn't doing anything to the images. The idea is to show them as thumbnails.

注意:我在Linux上使用emacs 24.2。
我可以使用M x image-dired显示缩略图,但是,我想在组织模式下显示固定大小的图像。

Note: I am using emacs 24.2 on Linux. I can show thumbs using M x image-dired, however, I want to show fixed size images under org mode. Normal images can already be shown.

推荐答案

我看过 org-display-inline-images source:
它只是调用 create-image 。在这一刻似乎没有缩放选项。

I've looked at org-display-inline-images source: it's just calling create-image. It seems there's no scaling options at this moment.

我已经写了一个小的工作。
这是一个黑客,但也许你想尝试一下。
什么:当org想要显示图像〜/ cat.jpg时,
这个函数使它看起来如果〜/ catt.png存在,并显示相反。
如果没有找到〜/ catt.png,则会调用ImageMagick的转换来创建它:

I've written a small work-around. It's a bit of a hack, but maybe you'd like to try it. What does: when org wants to display an image "~/cat.jpg", this functions makes it look if "~/catt.png" is present and show that instead. If "~/catt.png" isn't found, ImageMagick's convert is called to create it like so:

convert ~/cat.jpg -thumbnail 300x300 ~/catt.png

您可以自定义大拇指大小并输入并输入名称。
不要忘记安装ImageMagick。

You can customize the thumb size and type and name if you want. And don't forget to have ImageMagick installed.

(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))))))))))

这篇关于配置emacs显示固定宽度的内联图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆