14

I wish to display org mode inline image (in emacs) with width 400 but actually it always show it as original size.

My steps as below:

  1. Install ImageMagick with below command: sudo port install imagemagick
  2. Install emacs with below command: brew install emacs --HEAD --use-git-head --cocoa --with-gnutls --with-rsvg --with-imagemagick Then I check it, emacs version is GNU Emacs 26.0.50.1, but (image-type-available-p 'imagemagick) result is nil

  3. Edit ~/.emacs.d/init.el to add below line: (setq org-image-actual-width nil)

  4. Write below org code in test.org:

#+ATTR_ORG: :width 400 [[file:test.png]] 5. After run C-c C-x C-v,Image not displayed as 400 but actual size.

Drew
  • 75,699
  • 9
  • 109
  • 225
beetlej
  • 1,056
  • 1
  • 7
  • 20
  • To install graphic Emacs (Emacs.app) with ImageMagick support via MacPorts, use `sudo port install emacs-app +imagemagick`. It looks you are using MacPorts to install dependency for HomeBrew, I have no idea if it should work. and there is no need to install dependency manually at all, it is your package manager's job. Besides, using two package managers at a time is usually a bad idea and unnecessary. – xuchunyang Feb 08 '17 at 17:30
  • @xuchunyang Exactly, after reinstall emacs-app with port, it works fine now. Thanks – beetlej Feb 08 '17 at 21:02

3 Answers3

14
(setq org-image-actual-width 400)

should do the job. The documentation of the variable (C-h v org-image-actual-width RET) gives more detail:

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(sic) with imagemagick support.

NickD
  • 27,023
  • 3
  • 23
  • 42
8

Imagemagick version not match.

Change brew install command as below:

brew install emacs --with-cocoa --with-gnutls --with-dbus --with-librsvg --with-imagemagick@6 --with-mailutils --devel

Then run brew info emacs to check if magicmagick is fine!

emacs: stable 25.1 (bottled), devel 25.2-rc2, HEAD
GNU Emacs text editor
https://www.gnu.org/software/emacs/
/usr/local/Cellar/emacs/25.2-rc2 (4,051 files, 120.1MB) *
  Built from source on 2017-03-11 at 16:56:47 with: --with-cocoa --with-gnutls --with-dbus --with-librsvg --with-imagemagick@6 --with-mailutils
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/emacs.rb
==> Dependencies
Build: pkg-config ✔
Optional: dbus ✔, gnutls ✔, librsvg ✔, imagemagick@6 ✔, mailutils ✔

If imagemagick@6 is checked, then everything should be fine.

In emacs, run below command to check if imagemagick package available:

*** Welcome to IELM ***  Type (describe-mode) for help.
ELISP> (image-type-available-p 'imagemagick)
t
ELISP>
lucky1928
  • 1,622
  • 8
  • 28
  • This brew command didn't work for me in recent homebrew distro on macOS Catalina 10.15.5. Seems that homebrew devs dropped options support a year ago, see https://github.com/Homebrew/homebrew-core/pull/36070. – krvkir Jun 03 '20 at 14:58
6

In your step 2,

(image-type-available-p 'imagemagick)

should return t. nil is for unavailable. Perhaps the reason you get nil is the paths from macports install of imagemagick is not being picked up by the brew install of emacs. Have you noticed any compile errors to that effect?

In any case, adjust the path to imagemagick manually or install it from brew as well. Installing both imagemagick and emacs from macports works for me.

Emacs User
  • 5,553
  • 18
  • 48