Many thanks for your reply, Taco. It helps me a lot to manipulate the images (which are actually PDF documents). I have another question about an issue that I experience at work. Some of the PDF documents I have to deal with are poorly generated. There are misplaced A4 pages inside legal paper sizes. I thought there were malformed in such a way: \showframe \setuppapersize[A4][legal] \starttext \dorecurse{10}{\input{zapf}} \stoptext So my approach was: \setuplayout[page] \starttext \getfiguredimensions[a-test.pdf] \page[right]\dorecurse{\noffigurepages} {\externalfigure[a-test.pdf][page=\recurselevel]} \stoptext But after a closer inspection, the docuemnts are properly malformed. They include some top and left extra margins. Is there any way to remote those extra margins? (Offset doesn’t seem to work here.) Many thanks for your help again, Pablo On 1/28/20 5:04 PM, Taco Hoekwater wrote:
Hi Pablo,
I have had lots of problems with getting the correct figure dimensions for external images. In the end, I now use the code below. It is just as low-level and much more inefficient than your code, but it has not failed me yet.
\newdimen\MYfigurewidth \newdimen\MYfigureheight \unexpanded\def\MYgetfiguredimensions {\dodoubleempty\MYdogetfiguredimensions}
\def\MYdogetfiguredimensions[#1][#2]% {\setbox0=\hbox{\externalfigure[#1][#2]}% \MYfigurewidth=\wd0 \MYfigureheight=\ht0 }
And used like:
\MYgetfiguredimensions[cow.pdf][page=1] \ifdim\MYfigurewidth>\MYfigureheight … \fi
and I only use Hans’ \getfiguredimensions when I need to know a pdf page count.
It is not that Hans’ macro is bad, but external figures (especially PDF, but also PNGs) can be very misbehaved.
Actually forcing the inclusion into a box is crude but at least it will always return results identical to any actual desired inclusion.
Best wishes, Taco
On 28 Jan 2020, at 16:51, Pablo Rodriguez
wrote: Dear list,
I have to check whether an external PDF document is portrait or landscape (in order to manipulate it in different ways).
From what I understand of grph-inc.mkiv, I came with the following sample:
\unprotect \def\figureXSize{\clf_figurestatus{width}{}} \def\figureYSize{\clf_figurestatus{height}{}} \protect
\setupexternalfigures[location=default] \starttext \getfiguredimensions[cow.pdf] \figuresize\\ \figurelabel\\ \figureXSize\\ \figureYSize\\ \ifnum\figureXSize<\figureYSize portrait\else landscape\fi \stoptext
I feel bad of abusing the ConTeXt source in such a miserable way. But I’m afraid this is the best I can.
Is there no standard way to check portrait or landscape on a given figure? A conditional for that would be useful.
At least, I would like to know how to get image dimension numbers suitable to be deployed with \ifnum.
Many thanks for your help,
Pablo