According to various tools the images example-image-a.png and example-image-a.jpg from the mwe package both have size 400 x 300 pixels. However, the document



includes the pictures with different sizes. What determines the size at which the pictures are rendered, and why is it different in this case?

enter image description here

1 Answer 1


The JPEG file example-image-a.jpg does have resolution information:

Image file name = example-image-a.jpg

* File [example-image-a.jpg]
( FP-DIV ) ( FP-DIV )
  Type: jpg
  Pixel width: 400 px
  Pixel height: 300 px
  Density x: 90 dots per 72.27pt
  Density y: 90 dots per 72.27pt
  Width: 319.99911 bp
  Height: 239.99905 bp

The density lines mean: 90 DPI

The PNG file lacks information about resolution:

Image file name = example-image-a.png

* File [example-image-a.png]
( FP-DIV ) ( FP-MUL ) ( FP-DIV ) ( FP-DIV )
  Type: png
  Pixel width: 400 px
  Pixel height: 300 px
  Ratio x: 90
  Ratio y: 90
  Width: 399.99916 bp
  Height: 299.99965 bp

Therefore, a default resolution of 72 DPI is used.

The data are extracted with:

pdftex bmpsize-test

Setting of the default resolution

In case of pdfTeX, the default resolution can be set via \pdfimageresolution. This resolution is used, if pdfTeX cannot find resolution data in the bitmap file. The graphics driver file pdftex.def supports the setting of this resolution by option resolution:




Extracting resolution data (pdfTeX)

The resolution data can also be extracted from example-image-a.jpg and used for example-image-a.png via the help of package bmpsize-base.


% Macro \SetMacroToImageResolution{#1}{#2}
% #1: macro that gets the rounded DPI integer value as result
% #2: image file with extension
% Result: Macro #1 is defined with the
%   rounded image resolution in DPI as integer
%   or 0 if the image is not found
%   or the resolution data are not complete.
    % Try the supported image formats for pdfTeX in PDF mode
    % until the correct image format is detected
  \csname bmpsize@read@#1\endcsname{#2}%
  \ifbmpsize@ok % Image could be read
    % Test for complete resolution data
         % Resolution data present




  • 2
    Good to know that the graphics driver respects DPI metadata. I've actually encountered situations with files saved from the internet where the DPI ratio was corrupt or not present, causing the image to appear as a vertical or horizontal line in some viewers, so that's useful. (I ended up writing a small binary-editor script to fix that for JPEGs, but I seem to have lost it, oh well.)
    – JAB
    Oct 11, 2016 at 20:04
  • @heiko-oberdiek is there a way to make it have the resolution of another graphic? Oct 12, 2016 at 10:37
  • 1
    @MysticOdin See updated answer. Oct 12, 2016 at 17:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .