Setting the density in PSD and 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

Setting the density in PSD and PNG

Post by Drarakel »

I understand that the density has not the highest priority in IM. I mean, it would nedd a huge effort to get this information 'right' in every situation, with different routines for all the different formats - that's not worth it. That being said, perhaps in the two cases here, something could be changed. No real bugs, but it just doesn't look right at the moment.
I'm using the current IM version 6.6.8-0.

With PSD:

Code: Select all

convert rose: -set units PixelsPerInch -set density 100 rose.psd
identify -format "%x x %y" rose.psd
100 Undefined x 100 Undefined
No grave error so far. (IM does write everything into the Photoshop profile, but after that, reads only the density value from there. The units value would come from the XMP profile, but since there's no such profile here, it's Undefined.)
But now:

Code: Select all

convert rose: -set units PixelsPerCentimeter -set density 100 rose2.psd
identify -format "%x x %y" rose2.psd
127 Undefined x 254 Undefined
Double-checked with ExifTool:

Code: Select all

exiftool -S -XResolution -DisplayedUnitsX -YResolution -DisplayedUnitsY rose2.psd
XResolution: 127
DisplayedUnitsX: cm
YResolution: 254
DisplayedUnitsY: cm
:?

Apparently, IM thinks that the 100 PixelsPerCentimeter need to be converted to a PixelsPerInch value (although PSD of course can store PixelsPerCentimeter, and the PPC unit is even written to DisplayedUnitsX and DisplayedUnitsY). So, now it's 254 PixelsPerCentimeter instead of 100 PixelsPerCentimeter. And for the 'XResolution', it's somehow half of that value (127). Very strange..


And a small problem with PNG:

Code: Select all

convert rose: -set units PixelsPerInch -set density 300 rose.png
convert rose.png rose2.png
identify -format "%x x %y" rose2.png
300 PixelsPerCentimeter x 300 PixelsPerCentimeter

Also strange - but can be explained. In the first file, of course the correct value of 118.11 PixelsPerCentimeter gets written into the pHYs chunk (as it can't be PixelsPerInch). But: "-set density" also sets an artifact and this gets written as additional "density" tEXt chunk (with value 300). When again reading that file, the density value from the "density" chunk takes precedence over that from the pHYs chunk, and so it's suddenly 300 PixelsPerCentimeter - and the pHYs chunk also gets updated with that. And later density changes from of e.g. "-density" or "-resample" always get overridden with that initial density chunk...
Of course a very small problem.. and I know how to circumvent it. But maybe "-set density" shouldn't automatically create a "density" chunk (just like "-set units" doesn't automatically create a "units" chunk)?
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Setting the density in PSD and PNG

Post by glennrp »

I checked in a fix (IM-6.6.8-2, SVN r3815) to skip writing a text:density chunk if the pHYs chunk is being written.
Also (SVN r3816) to skip reading the text:density chunk if a pHYs chunk has been read.
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Setting the density in PSD and PNG

Post by Drarakel »

glennrp wrote:I checked in a fix (IM-6.6.8-2, SVN r3815) to skip writing a text:density chunk if the pHYs chunk is being written.
Also (SVN r3816) to skip reading the text:density chunk if a pHYs chunk has been read.
Thank you!
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Setting the density in PSD and PNG

Post by glennrp »

The fix did not work quite right; it was eliminating all of the PNG text
chunks. Fixed in IM-6.6.8-4, SVN r3845.
Post Reply