Org 中显示 inline 图片时,图片尺寸可以控制吗?

在EMACS中display inline的图片尺寸可以控制吗?有时候插入的图片很大,希望能设置一个最大宽度。

你已经尝试过什么了吗?比如看下文档里有没有现成的解决方法: (elisp) Showing Images

我之前问的,不知能否帮到你:

谢谢回复

这个链接里没提供设置inline图片尺寸的方法

我不明白什么意思?你能解释下吗?附上一张图片,举例子时或许能用得上。

  1. 在org文档中插入一张图片
  2. 按c-c c-x c-v来让他在行内显示

有是有插入的尺寸尺寸很大,会超出EMACS的编辑器范围,这时候希望能保持图片长宽比例的情况下把图片缩小。

有调查过 org-image-actual-width 选项吗?或许值得一试。C-h v org-image-actual-width

org-image-actual-width is a variable defined in `org.el'.
Its value is t

Documentation:
Should we use the actual width of images when inlining them?

When set to t, always use the image width.

When set to a number, use imagemagick (when available) to set
the image's width to this value.

When set to a number in a list, try to get the width from any
#+ATTR.* keyword if it matches a width specification like

  #+ATTR_HTML: :width 300px

and fall back on that number if none is found.

When set to nil, try to get the width from an #+ATTR.* keyword
and fall back on the original width if none is found.

This requires Emacs >= 24.1, build with imagemagick support.

You can customize this variable.

This variable was introduced, or its default value was changed, in
version 24.4 of Emacs.

Emacs 编译的期间需要开启 imagemagick 支持,查看有没有支持:

(image-type-available-p 'imagemagick)
     ⇒ t

我是在图片上一行加入: #+ATTR_ORG: :width 300px

1 个赞

我自己刚刚试了下,是有效果的。

调整默认设置:

(setq org-image-actual-width nil)
     ⇒ nil

测试 Org

#+ATTR_foo: :width 600px
[[file:Desktop/foo.png]]

Org mode version 9.0.3 (release_9.0.3-140-ged0c8c @ /Users/xcy/src/org-mode/lisp/)

没人这么用吗?我用着挺好的:

;;if there is a #+ATTR.*: width="200", resize to 200, otherwise resize to 400
(setq org-image-actual-width '(400))

关于org-image-actual-width

(setq org-image-actual-width 300) => always resize inline images to 300 pixels

(setq org-image-actual-width '(400)) => if there is a #+ATTR.*: width=“200”, resize to 200, otherwise resize to 400

(setq org-image-actual-width nil) => if there is a #+ATTR.*: width=“200”, resize to 200, otherwise don’t resize

(setq org-image-actual-width t) => Never resize and use original width (the default)

2 个赞

@xuchunyang @ziyuanjun

谢谢你们的帮助,但你们提供的设置我这里都不起作用。 我的操作系统是windows 7。

@xuchunyang

(setq org-image-actual-width nil)
     ⇒ nil

这个代码是一个整体吗?包括下面的箭头和nil? 我把这个箭头加入到init.el里后,启动emacs会报错: Symbol's value as variable is void: ⇒

请通过 C-h v 看下 org-image-actual-width 的说明,确保你明白这个选项的用法和使用前提(比如你的 Emacs 需要有 imagemagick 支持,假如压根就不支持的话,就不要再期望这个选项会起作用;假如你不是已经知道是否有 imagemagick 支持的话,可以看看 C-h v image-types 是否包含 imagicmagick)。

不是,不包括。那个 nil(setq org-image-actual-width nil) 的返回值, 是用来提示这个返回值(这是 Emacs Lisp Manual 中采用的记号: (info “(elisp) Evaluation Notation”))。

我感觉这条命令不起作用跟操作系统应该没关系

谢谢你耐心的解答,由于之前我自己无法解决这个问题,索性没管它。但是最近一个文档需要插入很多大图片,导致非常难受。

我按照你说的办法看了一下,我的EMACS版本是

GNU Emacs 25.1.1 (x86_64-w64-mingw32) of 2016-09-22

并不支持imagicmagick

我不是程序员,仅使用orgmode来写文档,不知道如何获得支持imagicmagick的EMACS windows版,我应该怎么办?

你需要安装 imagemagick: ImageMagick – Download 最下面是 windows 版本

windows下编译好的 emacs 一般都支持 imagemagick 的,你的不支持估计是没有安装 imagemagick 自身,安装完后记得设置路径环境变量

请问如何设置路径环境变量?

我安装了imagemagick,但没设置环境变量,现在依然不能改变图片大小

网络上有很多这方面教程

感谢你的帮助。 我的操作系统是windows 7 64位,我下载了最新版的imagemagick,安装到目录“c:\Program Files\ImageMagick-7.0.5-Q16\” ,把这个路径添加到了“系统属性→高级→系统变量→path”

没有重启电脑,重启emacs之后尝试设置images宽度

#+attr.*: :width 100
[[file:imgs/screenshot_20170221_211651.png]]

仍然不起作用

C-h v image-types查看,得到

我觉得你的环境变量设置的可能有问题:

检查你的 imagemagick 是否在 path 中,因为很多应用的可执行文件是在程序文件夹下面的 bin 文件夹下。你可以在你的 cmd 中执行 mogrify -help 命令验证一下,看是否可以执行。

mogrify -help 不能执行 magick -help 可以

另外,在imagemagick安装目录里面没有bin文件夹