How to get Image DPI in PixelPerInches

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
mjamal
Posts: 62
Joined: 2017-12-27T06:13:59-07:00
Authentication code: 1152

How to get Image DPI in PixelPerInches

Post by mjamal » 2019-01-08T06:23:04-07:00

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.

snibgo
Posts: 11590
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to get Image DPI in PixelPerInches

Post by snibgo » 2019-01-08T08:48:09-07:00

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'
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 24909
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to get Image DPI in PixelPerInches

Post by fmw42 » 2019-01-08T09:25:10-07:00

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.

Post Reply