Compare Imagick, Adobe Photoshop and Windows - Detect resolution (pixels per centimeter or pixels per inch)
P粉520204081
P粉520204081 2024-04-06 16:01:27
0
1
646

This is not a question, but an attempt to improve my understanding of how DPI is stored in various file formats, and discuss why it works.

I work a lot with images (JPG, PNG and Tiff) and detect their resolution.

For example, I can run this on an image in Imagick:

$imagick = new Imagick($filename);
$data = $imagick->identifyimage();
var_dump($data);

It will give me the resolution and units (PixelsPerCentimeter or PixelsPerInch)

In Windows (11), I can only see the resolution in the properties of the JPG but not the PNG, whether you set the PSD to PixelsPerCentimeter or PixelsPerInch, it shows up as ( 300 dpi).

In Imagick (version: ImageMagick 6.9.11-60 Q16 x86_64) - it is able to see the difference between a JPG saved with PixelsPerCentimeter and a JPG saved with PixelsPerInch. But for PNG, no matter how I create/save it in Photoshop, it gives PixelsPerCentimeter.

Photoshop (24.1.0) can also detect PixelsPerCentimeter on JPGs - but the PNGs all "say" they are PixelsPerInch, even if I save them as PixelsPerCentimeter.

Now I totally understand 118.11 PixelsPerCentimeter = 300 PixelsPerInch but I'm really interested in why Windows/Photoshop and Imagick treat them like this?

I did consider that creating the file in Photoshop initially might have side effects, so I created a file using Imagick (PNG, 300dpi, PixelsPerInch), but Imagick specified it as 118 PixelsPerCentimeter.

So I guess my question is: Do these differences depend on how the file is read or the actual metadata stored in the file type?

P粉520204081
P粉520204081

reply all(1)
P粉885562567

This is not an authoritative, complete answer - more like a "hint" since no one answered you.

This is a bit like a minefield, different software has different lengths. If you want to explore it further, exiftool and its -v option are usually the most helpful.


About PNG images

The original PNG specification has a pHYs block that only gives horizontal and vertical resolution in meters, inches are not available. HereThe various PNG tags are described.

Some software (ImageMagick and exiftool) store (JPEG-style) APP1 data (see below) informally in zTXt blocks. Some don't.

In July 2017, the PNG specification was updated to allow eXIf blocks. See here.


About JPEG images

In JPEG, x/y resolution may be stored in the APP0, APP1, or APP13 (Photoshop) segments. The best description I know is here.

I've never been that interested in XMP data, but I believe x/y resolution might be stored there as well.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template