That is, I have a PNG graphic, using pdflatex and the graphicx package:
\includegraphics{myfile}
where myfile.png is 384 pixels in width. Since the graphic info shows it's
set to 96dpi, I figured it would print at 4inches, which was what I really
wanted.
Instead it printed at a bit over 5 inches; I bet it's because LaTeX sees
bitmap files as if they're 72dpi, but I'm just guessing.
My question is what pixel width should the raw image be in order to get a
4inch wide figure in the final pdf? I do know I can use scaling and width=
keyword in includegraphics, but for other reasons I need to not do that in
this case.
thanks,
--Tim Arnold
Let me suggest first converting the PNG to EPS if you're using LaTeX
or PDF if you're using PDFLaTeX and working with the EPS/PDF instead.
The best method that I have seen for doing this conversion is sam2p.
It does a great job at placing a vector "wrapper" around the raster
image without significantly changing the quality of the image. You
can get sam2p from
http://www.inf.bme.hu/~pts/sam2p/
or you can use my web converter (which uses sam2p) at
http://www.tlhiv.org/rast2vec/
After you have converted the PNG, you can do
\includegraphics[width=4in]{foo.eps}
if you are using LaTeX or
\includegraphics[width=4in]{foo.pdf}
if you are using PDFLaTeX. You might also consider reading this page.
http://www.tlhiv.org/graphics/
Troy Henderson
See pdftex manual:
\pdfimageresolution (integer)
The integer \pdfimageresolution parameter (unit: dots per inch, dpi) is
a last resort value, used only for bitmap (jpeg, png, jbig2) images,
but not for pdfs. The priorities are as follows: Often one image
dimension (width or height) is stated explicitely in the TEX file. Then
the image is properly scaled so that the aspect ratio is kept. If both
image dimensions are given, the image will be stretched accordingly,
whereby the aspect ratio might get distorted. Only if no image
dimension is given in the TEX file, the image size will be calculated
from its width and height in pixels, using the x and y resolution
values normally contained in the image file. If one of these resolution
values is missing or weird (either < 0 or > 65535), the
\pdfimageresolution value will be used for both x and y > resolution,
when calculating the image size. And if the \pdfimageresolution is
zero, finally a default resolution of 72 dpi would be taken. The
\pdfimageresolution is read when pdfTEX creates an image via
\pdfximage. The given value is clipped to the range 0..65535 [dpi].
Currently this parameter is used particularily for calculating the
dimensions of jpeg images in exif format (unless at least one dimension
is stated explicitely); the resolution values coming with exif files
are currently ignored.
--
Ulrike Fischer
Thanks Ulrike, that explains it quite well. After I read your answer, I
googled for pdfimageresolution and saw that this is a fairly common
question. I just couldn't google the right thing beforehand.
My problem was that I started off with png images that said they were 96dpi,
but then I manipulated them and accidentally cleared their 'info'
dictionaries--that's why pdflatex used 72dpi as the last resort.
Now I can set the dpi in the info dictionary to match the final width I need
(depending on the number of pixels available of course...). I *could* set
the width= and be done with it, but for this situation I can't do that (I
have more control over the png images than I have with the writers)
thanks!
--Tim Arnold