# [texhax] Retrieve graphics measurments

Tue Jul 20 23:13:56 CEST 2010

On Tue, Jul 20, 2010 at 04:41:23PM -0400, Marshall Feldman wrote:

> On Fri Jul 9 23:15:29 CEST 2010, Martin Schröder martin at oneiros.de wrote:
>
> >2010/7/9 Marshall Feldman<marsh at uri.edu  <http://tug.org/mailman/listinfo/texhax>>:
> >/>  I am a very new LaTeX user. I've searched all over and cannot find this
> />/>  information. My question is, how does one retrieve the dimensions of an
> />/>  inserted graphic?
> /
> >\settowidth et.al.
>
> 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}}

\newlength{\myboxheight}
\setlength{\myboxheight}{\ht\mybox}

> or even
>
>    \setlength{\myboxheight}{\height{myfig}}

\usepackage{calc}
\setlength{\myboxheight}{\heightof{\usebox{\mybox}}}

or

\settoheight{\myboxheight}{\usebox{\mybox}}

Yours sincerely
Heiko Oberdiek