[texhax] Retrieve graphics measurments
Stephen Hicks
sdh33 at cornell.edu
Tue Jul 20 23:03:57 CEST 2010
On Tue, Jul 20, 2010 at 1:41 PM, Marshall Feldman <marsh at uri.edu> wrote:
> Sorry, but I should have been more explicit. I'm trying to develop a class
> for letterhead stationary that will allow the user to specify one of several
> graphics to appear in the header. So to get the page layout right, it's
> important to measure the height of the graphic accurately, depending on
> which graphic is specified.
>
> Suppose I have an encapsulated PostScript (eps) file containing the
> following two lines:
>
> %%BoundingBox: 0 0 543 388
> %%HiResBoundingBox: 0 0 542.7368 387.7378
>
> From this information, the aspect ratio (h/w) is 388/543 = 0.7145.
>
> Now I read this figure into my LaTeX document using the graphicx package and
> the following LaTeX code:
>
> \newsavebox{\mybox}
> \sbox{\mybox}
> {\makebox[2.0in][l]
> {\includegraphics[width = 2.0in]{myfig}}}
>
> With the 2.0in width, the height of the box and included graphic should be 2
> x 0.7145 = 1.43in. But how does one find this out within LaTeX?
>
> What I'd like to do is:
>
> \newlength{\myboxheight}
> \setlength{\myboxheight}{\height{mybox}}
>
> or even
>
> \setlength{\myboxheight}{\height{myfig}}
>
> But there doesn't seem to be any way to do this. Every example I can find on
> the web calls for the user figuring out the height manually. Suppose, for
> example, we wanted the class to allow the user to specify not only which
> graphic to use but also its scale by specifying its width. Now there would
> be absolutely no way to know the height until the user specifies it.
>
> Surely there must be a way to do this.
What you're looking for is
\setlength\myboxheight{\ht\mybox} % note: \ht{mybox} or \ht{\mybox}
is wrong and will not work.
You can get the width with \wd\mybox (and the depth if it's there with
\dp\mybox, though images should have no depth).
This is plain TeX and will work just fine with LaTeX, though maybe
LaTeX has its own version of these primitives.
Cheers,
steve
More information about the texhax
mailing list