[texhax] Retrieve graphics measurments

Marshall Feldman marsh at uri.edu
Tue Jul 20 22:41:23 CEST 2010


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.

>Best
>    Martin

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.

Thanks.

     Marsh Feldman

-- 
Dr. Marshall Feldman, PhD
Director of Research and Academic Affairs
CUSR Logo
Center for Urban Studies and Research 
<http://www.uri.edu/prov/research/urbanstudies.html>
The University of Rhode Island <http://www.uri.edu>



More information about the texhax mailing list