Greetings, I have many images, all with different aspect ratios, that I would like to collect in a document. Each image should be rotated and scaled to fit its page. My MWE uses an image's width and height to discern whether it's wide, tall, or square. This works, but I feel I'm reinventing the wheel. Is there a more straightforward way to implement this? Any suggestions would be much appreciated.
--
With kind regards,
Michael Guravage
\showgrid
\setuplayout
[header=0pt, footer=0pt,
topspace=0pt, bottomspace=0pt,
height=middle, width=middle,
backspace=0pt]
\starttext
\startluacode
require "lfs"
function GetFileExtension(url)
return url:match("^.+(%..+)$")
end
cwd=lfs.currentdir()
for file in lfs.dir(cwd) do
suffix = GetFileExtension(file)
if suffix == ".png" then
image = figures.getinfo(file).used
width = image.width or 0
height = image.height or 0
aspect = height/width
if (aspect > 0.9 and aspect < 1.1 ) then
context.externalfigure({file},{width="\\textwidth"}) -- almost
square
elseif height < width then
context.externalfigure({file},{width="\\textheight",
orientation=90}) -- landscape
else
context.externalfigure({file},{height="\\textheight"}) -- portrait
end
context.page()
end
end
\stopluacode
\stoptext
\showgrid
\setuplayout
[header=0pt, footer=0pt,
topspace=0pt, bottomspace=0pt,
height=middle, width=middle,
backspace=0pt]
\starttext
\startluacode
require "lfs"
function GetFileExtension(url)
return url:match("^.+(%..+)$")
end
cwd=lfs.currentdir()
for file in lfs.dir(cwd) do
suffix = GetFileExtension(file)
if suffix == ".png" then
image = figures.getinfo(file).used
width = image.width or 0
height = image.height or 0
aspect = height/width
if (aspect > 0.9 and aspect < 1.1 ) then
context.externalfigure({file},{width="\\textwidth"}) -- Almost square
elseif height < width then
context.externalfigure({file},{width="\\textheight", orientation=90}) -- landscape
else
context.externalfigure({file},{height="\\textheight"}) -- portrait
end
context.page()
end
end
\stopluacode
\stoptext
scaleme.pdf
Description: Adobe PDF document
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : [email protected] / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror) archive : https://github.com/contextgarden/context wiki : https://wiki.contextgarden.net ___________________________________________________________________________________
