Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

When I include bitmap images in my PDF files (created with pdflatex and the graphicx package), I always check manually that the resolution will be suitable (I shoot for something between 200 and 300 dpi). I just realized it’s a pity to do it by hand, while LaTeX actually knows both the pixel size of the image and its final size on paper.

Is it possible to have LaTeX issue a warning when the resolution of an included bitmap image will be outside certain bounds?

share|improve this question
1  
If you want to print your pdf all included pictures should be in the same resolution, for example 300 dpi or 600 dpi or 1200 dpi, depending on the needed print quality. So you should prepare them to be included without scaling in the needed width/hight and resolution. –  Kurt Oct 28 '12 at 21:45
add comment

1 Answer

up vote 4 down vote accepted

LaTeX neither knows the resolution nor the final size on the paper:

  • \includegraphics prints the requested sizes in the .log file with driver pdftex.def:

    Package pdftex.def Info: foobar.png used on input line 5.
    (pdftex.def)             Requested size: 67.0pt x 89.0pt.
    

    But \includegraphics can be put inside \scalebox or \resizebox, for example. Thus the final size on the paper is not known, when \includegraphics is executed.

  • The terminal output and the .log file also contain something like:

    <foo.png, id=1, 12pt x 34pt>
    

    That is printed by the driver part of pdfTeX. It is the natural size of the image that would be the size of the image, if the image is included by pdfTeX without further scaling.

  • \pdfimageresolution is only considered, if the image does not contain resolution data.

What can be done:

  • Reading the .log file by a script that takes the natural size, the requested size, the image file name. Then it can calculate the scale factor and can apply it to the resolution. The script gets the resolution by running an external program (e.g. file in Linux) or by analyzing the image. But this method will not detect later scalings.

  • Package bmpsize analyzes bitmap images. The method there can be used to get the resolution at TeX macro level. The package itself terminates for pdfTeX in PDF mode, originally because it is not needed to calculate the size of the image, that pdfTeX in PDF mode already is able to do itself. Again, later scalings are difficult to track.

  • Parsing the PDF file directly. Then the settings of the current transfer matrix can be tracked and applied to the resolution of the bitmap image data. Also this method can find images inside PDF Form XObjects, that are missed by the previous methods (pdfTeX can include PDF files that contain bitmap images).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.