27

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.

don_crissti
  • 79,330
  • 30
  • 216
  • 245
nath
  • 5,430
  • 9
  • 45
  • 87
  • 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 03:40
  • 1
    what user interfaces are acceptable? – Jasen Nov 23 '17 at 05: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

3 Answers3

37

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.


don_crissti
  • 79,330
  • 30
  • 216
  • 245
  • 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
  • 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 Nov 24 '17 at 11:03
  • Don't know if it changed but the default is now `PixelsPerInch`, with ImageMagick 7.1.1-12 – Pascal Polleunus Jul 11 '23 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. – don_crissti Jul 11 '23 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 – Pascal Polleunus Jul 12 '23 at 16:53
  • @PascalPolleunus - if your PNG has `Units: Undefined` (run `identify -verbose` on your png file) then probably IM converts to PPI... – don_crissti Jul 12 '23 at 18:38
  • @don_crissti Yes, `Units: Undefined` – Pascal Polleunus Jul 13 '23 at 19:45
8

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

Jasen
  • 3,715
  • 13
  • 14
  • 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 Nov 23 '17 at 18:17
0

For exiftool tag names for PNG see the man-page

Usage example

$ exiftool -p "$PixelsPerUnitX,$PixelsPerUnitY,$PixelUnits" image.png  
11811,11811,meters 
AdminBee
  • 21,637
  • 21
  • 47
  • 71