user1323995
user1323995

Reputation: 1366

How to resize images in org-mode

Is there a general way to define the size, in percent or pixels, for an image that is linked in org-mode?

Say I have the following link in my .org file:

[[~/images/example.jpg]]

This JPG is way too large, so if I export it to HTML or LaTeX or open it in org-mode with C-c C-o i will only see a fraction of the image.

Upvotes: 77

Views: 58922

Answers (7)

dat
dat

Reputation: 1720

For export to LaTeX, if you hope to 'scale' the image (a la Alioth's response for HTML), there are a few ways to go.

Scaling relative to the image size:

#+ATTR_LATEX: :scale 1.2

Scaling relative to what LaTeX thinks is going on with the typesetting:

#+ATTR_LATEX: :width 0.40\linewidth

#+ATTR_LATEX: :width 0.5\textwidth

Upvotes: 1

Adam
Adam

Reputation: 2255

As per Jacobo's comment, add the following to your init.el file:

(setq org-image-actual-width nil)

Then in org-mode, you can precede each JPG, PNG, and SVG as shown in the following example to adjust the size of each inlined image.

#+ATTR_ORG: :width 100
[[~/images/example.svg]]

If you want to size this for both inline previews and html output:

#+ATTR_HTML: width="100px"
#+ATTR_ORG: :width 100
[[~/images/example.svg]]

Upvotes: 70

zkytony
zkytony

Reputation: 1508

Here is a way to resize images in emacs Org mode for preview (not exporting). Typically,

  1. We want to set an image to a specific width like 249px when we need to.
  2. We want to set a default image width, so that we don't need to specify +attr_html for every image - that would be tedious.

This can be achieved by configuring org-image-actual-width like follows:

(setq org-image-actual-width (list 550))

Then, in your .org file, if you have

#+attr_html :width 249
[[~/images/example1.jpg]]

then the image will be displayed in preview at width 249px. For another image, where no +attr_* is specified, the default width of 550px will be applied.

[[~/images/example2.jpg]]

You can see this behavior from the documentation in org-mode source code:

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.

I found it hard to understand what does "a number in a list mean", so I looked at the implementation, and indeed, something like (list 550) works.

Upvotes: 11

yPhil
yPhil

Reputation: 8377

As of Org 8.0, "Attribute lines now take plists" :

#+attr_html: :width 100px
#+attr_latex: :width 100px
[[~/images/example.jpg]]

Upvotes: 97

6pi
6pi

Reputation: 417

For LaTeX, to remove the default width=.9\linewidth, set the org-latex-image-default-width to empty string. By this way, the image will have its natural size.

To do that on the fly use the set-variable emacs command. Or to set this variable permanently, add the following line in your init.el : (setq org-latex-image-default-width "")

Upvotes: 4

Alioth
Alioth

Reputation: 603

This is a sample on how to resize an image using percentages (Org mode version 9.0.5):

#+CAPTION: Weight space                                                                                                                                     
#+ATTR_HTML: :alt neural network :title Neural network representation :align right                                                                          
#+ATTR_HTML: :width 50% :height 50%                                                                                                                         
https://i.sstatic.net/nzHSl.jpg

Upvotes: 14

bzg
bzg

Reputation: 2605

#+ATTR_HTML: width="100px"
[[~/images/example.jpg]]

Upvotes: 15

Related Questions