[texhax] Retrieve graphics measurments
Lars Madsen
daleif at imf.au.dk
Tue Jul 20 23:07:01 CEST 2010
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.
>
>> 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
>
\ht\mybox = height above baseline
\dp\mybox = depth below baseline
\wd\mybox = width
very handy to know
\usepackage{calc}
\setlength\myboxheight{\ht\mybox+\dp\mybox}
/daleif
More information about the texhax
mailing list