public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Lua filter: how to access image properties
@ 2019-10-21 17:48 ChrisD
  0 siblings, 0 replies; only message in thread
From: ChrisD @ 2019-10-21 17:48 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

I am trying to write a lua filter that adjusts the width attribute for an image. I want to get the actual dimensions of the image in pixels, and then set the {width} attribute of the image to the width in pixels.

(Motivation: In html output, the default width is already the actual image width in pixels. But in PDF output, the default width is 100%. I have a large document with many screenshots, and the screenshots look bad if you resize them. So I am trying to set the width to the actual image width so they won't be resized in PDF output.)

I have written a simple lua filter that processes every image object. In it I can get el.attributes["width"], which is the value of the {width} attribute in the markdown source (or nil if none is specified). I can set that attribute as well.

But how do I get the width of the actual image?

Is the image in pandoc.mediabag? If so, how do I access it? I found examples of how to add (insert) new images in the media bag, but not how to find ones that should already be there. And if it is in the mediabag, is the width (and height and other properties) available?

If the information is not in the media bag, it looks like I can open the original file using

   local im = pandoc.Image({}, el.src)

but then how do I get the width and height?

Also, is there a way to get the full path to the image file? The el.src (where el is the parameter to the Image function) is the path from the markdown. If the image is in a resource directory, I need to prepend the appropriate path from resource-dir. Ideally the full path to the file is available somewhere. If not, is the value of resource-dir available so I can parse it and search for it myself?

In general, is there any additional documentation on the data structures beyond https://pandoc.org/lua-filters.html? For example, what is the internal structure of the mediabag.

Thanks for your help
Chris

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/64431a4b-8242-1913-49fb-348bc66e5cc2%40intielectronics.com.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-10-21 17:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-21 17:48 Lua filter: how to access image properties ChrisD

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).