30

If I export an image with lets say 300 DPI and I read out its meta-info with any application that can do it (like file, exiftool, identify,mediainfo etc.), I always get a value showing Image-Width and Image-Height.

In this case: 2254 x 288

how do I get the 300 DPI value, or the corresponding value from any other image file?

Since in my case the proportional value of Image-Width and Image-Height does not matter I want to be able to check the resolution of any image to be able to compile new images with the same quality independent of their proportion, since this varies on every file.

For my workflow I'm especially interested in any command line solution, though any others are of course highly appreciated too.

3
  • 3
    PNG can store a pixels/meter value, but if you want to create a 2254x288 PNG, just do that. Physical sizes don't need to come into consideration
    – Fox
    Commented Nov 23, 2017 at 3:40
  • 1
    what user interfaces are acceptable?
    – Jasen
    Commented Nov 23, 2017 at 5:21
  • @Jasen, thank you for you replay and sorry for not making it clear acceptable are any command line interface applications. ==> I'll edit my question...
    – nath
    Commented Nov 23, 2017 at 17:53

3 Answers 3

42

You could use identify from imagemagick:

identify -format '%x,%y\n' image.png

Note however that in this case (a PNG image) identify will return the resolution in PPCM (pixels per centimeter) so to get PPI (pixels per inch) you need to add -units PixelsPerInch to your command (e.g. you could also use the fx operator to round value to integer):

identify -units PixelsPerInch -format '%[fx:int(resolution.x)]\n' image.png

There's also exiftool:

exiftool -p '$XResolution,$YResolution' image.png

though it assumes the image file has those tags defined.


7
  • thank you for your answer just been truing your suggestions, but by using the exiftool command I get Warning: [Minor] Tag 'XResolution' not defined - file.png; with the identify command I get: 118.10999999999999943,118.10999999999999943 how does this value correlate to the used 300DPI?
    – nath
    Commented Nov 24, 2017 at 10:02
  • 5
    thanks again, that was the right pointer! I now use identify -verbose -units PixelsPerInch file.png | grep Resolution outputs: Resolution: 300x300 if you want to add that to your answer you are welcome, it is accepted anyway!
    – nath
    Commented Nov 24, 2017 at 11:03
  • Don't know if it changed but the default is now PixelsPerInch, with ImageMagick 7.1.1-12 Commented Jul 11, 2023 at 18:25
  • @PascalPolleunus - I have the same version (7.1.1-12) and the units for PNG image defaults always to PPC not PPI. Commented Jul 11, 2023 at 21:02
  • @don_crissti Same results with PNG and JPG. identify -format '%x\n' image.png ⇒ 72 / identify -units PixelsPerInch -format '%x\n' image.png ⇒ 72 / identify -units PixelsPerCentimeter -format '%x\n' image.png ⇒ 28.346456692913385211 Commented Jul 12, 2023 at 16:53
8

open it with "the gimp" and click [image] -> [image properties]

1
  • 3
    hey that seems to go in the right direction, if open an image I compiled with 300 DPI i get the value 299,999 × 299,999 PPI for the resolution. Do you have any command-line solution to grep this value of a PNG file?
    – nath
    Commented Nov 23, 2017 at 18:17
1

For exiftool tag names for PNG see the man-page

Usage example

$ exiftool -p "$PixelsPerUnitX,$PixelsPerUnitY,$PixelUnits" image.png  
11811,11811,meters 

You must log in to answer this question.

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