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
    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 Nov 23 '17 at 3:40
  • 1
    what user interfaces are acceptable? – Jasen Nov 23 '17 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 Nov 23 '17 at 17:53

You could use identify from imagemagick:

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

Note however that identify will return the resolution in PPCM1 (pixels per centimeter) instead of PPI (pixels per inch) so you might need to add -units PixelsPerInch to your command.

There's also exiftool:

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

though it assumes the image file has those tags defined.

1: see this thread on their forum

  • 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 Nov 24 '17 at 10:02
  • 2
    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 Nov 24 '17 at 11:03

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

  • 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 Nov 23 '17 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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