Page 1 of 1

How to get Image DPI in PixelPerInches

Posted: 2019-01-08T06:23:04-07:00
by mjamal
Hello Team,

Can anyone please let me know how can I get the image resolution (DPI) with the units also for the PNG / BMP images?
I am using the below command but it is giving me DPI in PixelPerCentimeter and I need the unit in PixelPerInches.

exec("identify -format '%x' -units 'PixelsPerInch' jeanrightleg.png")

It was working for ImageMagick 6.7 but when I upgraded the ImageMagick version to 7.0.8 then it is not works as expected.

I am using CentOS 7.6
ImageMagick 7.0.8

Below is the image URL.
https://www.dropbox.com/s/0jga5x4d9qcaa ... g.png?dl=0

Thanks in advanced.

Re: How to get Image DPI in PixelPerInches

Posted: 2019-01-08T08:48:09-07:00
by snibgo
It seems to work for me, with v7.0.7-28 on Windows 8.1:

Code: Select all

f:\web\im>%IMG7%magick identify -format '%x' -units PixelsPerInch jeanrightleg.png
'72.010000000000005'

f:\web\im>%IMG7%magick identify -format '%x' jeanrightleg.png
'28.350000000000001'

Re: How to get Image DPI in PixelPerInches

Posted: 2019-01-08T09:25:10-07:00
by fmw42
For me on IM 7.0.8.23 Q16 Mac OSX, the image shows no Resolution and undefined units using

Code: Select all

magick identify -verbose image.png
So I presume Imagemagick assumes 72 dpi (converted to dpc for png).

But when I do that command, I get 72 both times.

Code: Select all

magick identify -format '%x' -units PixelsPerInch image.png
72

magick identify -format '%x' image.png
72
This would be a change and bug if it indeed worked in previous versions.