How to disable pandoc magnifying images to full width

Viewed 326

I'm trying to include different sized pictures in a pandoc markdown file - some are big, and some are small. When I render this via pandoc, by default it stretches/magnifies all images to be of full width, making the small images very large and blurry. Is there a way to disable this? The behaviour is consistent across PDF, DOCX and HTML output.

1 Answers

The size of an image can be set explicitly by setting the width and height attributes:

![small image](icon.png){width=64px height=64px}

![large image](landscape.jpg){width=1024 height=768}

It's possible to automate this, e.g. with the help of a Lua filter and Image Magick's identify:

-- pass this file to pandoc via `--lua-filter=filename.lua`

function Image (img)
  -- get dimensions
  local width, height = nil, nil -- implement
  img.attributes.width = width
  img.attributes.height = height
  return img
end
Related