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
Posts: 62
Joined: 2017-12-27T06:13:59-07:00
Authentication code: 1152

How to get Image DPI in PixelPerInches

Post 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. ... g.png?dl=0

Thanks in advanced.
Posts: 12159
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 »

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

f:\web\im>%IMG7%magick identify -format '%x' jeanrightleg.png
snibgo's IM pages:
User avatar
Posts: 25562
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 »

For me on IM 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

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