density in PNG

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

density in PNG

Post by Drarakel »

Another confusing issue with the density..
I know that there can be sometimes a problem when there are different density values in different profiles. Well, one could say, that's the fault of such input files.
But I have an example where the same density value is stored in the profiles - and there can be still a problem in ImageMagick with that value.

Take that image:
rose.tif
That file has a normal EXIF profile - and I also inserted a Photoshop (8BIM) profile. Both profiles have the same values for the horizontal density, the vertical density and the unit - I used 300x300 PixelsPerInch in this example. There are no other values in that file!
At this point, ImageMagick still displays the correct values of course:

Code: Select all

identify -verbose rose.tif
Resolution: 300x300
Units: PixelsPerInch

Code: Select all

identify -format "%x x %y" rose.tif
300 PixelsPerInch x 300 PixelsPerInch

Now conversion #1 to PNG:

Code: Select all

convert rose.tif rose1.png
identify -verbose rose1.png
Resolution: 300x300
Units: PixelsPerCentimeter

Code: Select all

identify -format "%x x %y" rose1.png
118.11 PixelsPerCentimeter x 118.11 PixelsPerCentimeter

And after a second PNG conversion:

Code: Select all

convert rose1.png rose2.png
identify -verbose rose2.png
Resolution: 300x300
Units: PixelsPerCentimeter

Code: Select all

identify -format "%x x %y" rose2.png
300 PixelsPerCentimeter x 300 PixelsPerCentimeter

So, one gets 300 PixelsPerCentimeter (762dpi) instead of 118.11 PixelsPerCentimeter (300dpi).
I was using IM v6.6.4-2 Q16, on Windows XP.


More details:
I think, when reading the TIF file, ImageMagick takes the horizontal and vertical density from the Photoshop profile and the unit from the EXIF profile. Then, for the conversion to PNG, IM has to convert the value from inches to centimeters and automatically stores 11811 pixels per meter in the pHYs chunk in this example. So far, there's no problem (as all original values in the TIFF are ok). But IM also stores the Photoshop profile as compressed text chunk (with the original 300 PixelsPerInch!). When reading from that PNG, IM takes the unit from the pHYs PNG chunk - but takes the horizontal and vertical density from this Photoshop profile in PNG! In the first PNG conversion, the file is still ok (IM only displays the wrong value). But in the second PNG conversion, IM writes this wrong value also into the pHYs chunk...
Additionally, I'm also wondering why 'identify -verbose' and 'identify -format "%x %y"' display different values. 'identify -verbose' can take the values from various places (as described before) - but 'identify -format' seems to take the values just from the pHYs chunk here.

I think: The behaviour that takes the elements for the density (the horizontal density, the vertical density and the units value) from different places can be problematic. (Especially in PNG files - as the normal pHYs chunk can't store the values as PixelsPerInch.)
The problems would be avoided if the elements for the density were always taken from the same place. The density value could still be taken from the Photoshop profile (if there's no pHYs chunk), but then the units value should be taken from there, too.
Is this possible? (Perhaps at least for PNG files?)
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: density in PNG

Post by glennrp »

I think this is fixed now, as of IM-6.6.8-5, SVN revision 3872.
Post Reply