Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find pixels per inch (PPI) using ImageMagick

I can get PPI for a JPEG image using the following command:

$ identify -format "%w x %h %x x %y" mypic.jpg 
1600 x 1200 72 PixelsPerInch x 72 PixelsPerInch

However, when I run the same command on PNG format I get Pixels Per Centimeter:

$ identify -format "%w x %h %x x %y" mypic.png 
1600 x 1200 28.35 PixelsPerCentimeter x 28.35 PixelsPerCentimeter

Is there a way to change the command to get Pixels Per Inch (PPI) for PNG format as well or perhaps calculate the PPI based on the pixels per centimeter?

like image 949
Jayson Avatar asked Jan 31 '13 18:01

Jayson


2 Answers

You can simply add the option

-units PixelsPerInch
like image 79
ybeltukov Avatar answered Oct 28 '22 10:10

ybeltukov


The resolution and units used are stored in the file, so if the resolution is stored in PixelsPerCentimeter, that's how identify will display it. There isn't a way to do the conversion automatically through identify. But it's just cm to inch conversion math:

PixelsPerInch = PixelsPerCentimeter * 2.54
like image 45
WWW Avatar answered Oct 28 '22 10:10

WWW