Possible bug: convert from PNG with resize|scale to PNG
Posted: 2018-08-26T04:56:37-07:00
[IM version: ImageMagick 6.8.9-9 Q16 x86_64 2018-07-10] - Linux Mint 18.3 Sylvia
[libpng versions: libpng16.so.16.20.0 + libpng12.so.0.54.0 ] - Linux Mint 18.3 Sylvia
Hello,
when converting a PNG file utilizing the scale or resize parameter to a new PNG file, the final PNG file lacks the Y Resolution EXIF (IFD0) tag. Instead, Pixels per unit X and Pixels per unit Y appear as new additional tag definitions. See the following minimal test case log:
In consequence of this behaviour (bug or feature?), resulting PNG images will show up distorted (vertically stretched) in several professional level software like Lightroom, Creative Cloud, XnView ... and possibly others. The distortion is not visible when sharing on Facebook or in private website galleries. They are also not visible in any image viewer or Gimp or file managers in my whole Linux desktop system - with the single excepttion of XnView.
I believe, the distorion happens because of the "new" definition of Pixels Per Unit X and Pixels Per Unit Y in the resulting PNG file. Possibly, these new values are calculate somehow with X Resolution and Y Resolution. As the latter is not defined, the display algorithms may use X Resolution and Pixels Per Unit X to calculate the width of the image to be displayed. Then, the same calculation happens for the Y axis (image height) and - due to the lack of Y Resolution - a default value for the missing Y Resolution is probably used to calculate the display height, possibly the common 72.
Example calculation (just a wild guess):
11811 PixelsPerUnitX / 300 XResolution = 39,37
11811 PixelsPerUnitY / 72 (common "default" resolution) = 164,04
So, if the X and the Y resolution differ severely after this calculation, the image will become severly distorted in either direction, also.
Help me: If someone knows of a workaround, meanwhile, I would be grateful to get to know it.
TIA and regards,
too
# Note: I use imagick in text terminals (BASH shell) on up-to-date Linux systems only.
[libpng versions: libpng16.so.16.20.0 + libpng12.so.0.54.0 ] - Linux Mint 18.3 Sylvia
Hello,
when converting a PNG file utilizing the scale or resize parameter to a new PNG file, the final PNG file lacks the Y Resolution EXIF (IFD0) tag. Instead, Pixels per unit X and Pixels per unit Y appear as new additional tag definitions. See the following minimal test case log:
Code: Select all
# 0: Check file.png (source file): X Resolution is defined, Y Resolution is defined.
exiftool -xresolution -yresolution -pixelsperunitx -pixelsperunity file.png
X Resolution : 300 # X Resolution is defined
Y Resolution : 300 # Y Resolution is defined
? # Pixels Per Unit X - UNDEFINED!
? # Pixels Per Unit Y - UNDEFINED!
# 1: Create new scaled (or resized) JPEG from source file:
convert file.png -scale 3000x3000 -quality 100 filenew.jpg
exiftool -xresolution -yresolution file.png
X Resolution : 300 # X Resolution is defined
Y Resolution : 300 # Y Resolution is defined
? # Pixels Per Unit X - UNDEFINED!
? # Pixels Per Unit Y - UNDEFINED!
# 2: Create new scaled (or resized) PNG from source file:
convert file.png -scale 3000x3000 -quality 100 filenew.png
X Resolution : 300 # X Resolution still defined!
# Y Resolution UNDEFIND / MISSING
Pixels Per Unit X : 11811 # Pixels Per Unit X - NOW DEFINED!
Pixels Per Unit Y : 11811 # Pixels Per Unit Y - NOW DEFINED!
I believe, the distorion happens because of the "new" definition of Pixels Per Unit X and Pixels Per Unit Y in the resulting PNG file. Possibly, these new values are calculate somehow with X Resolution and Y Resolution. As the latter is not defined, the display algorithms may use X Resolution and Pixels Per Unit X to calculate the width of the image to be displayed. Then, the same calculation happens for the Y axis (image height) and - due to the lack of Y Resolution - a default value for the missing Y Resolution is probably used to calculate the display height, possibly the common 72.
Example calculation (just a wild guess):
11811 PixelsPerUnitX / 300 XResolution = 39,37
11811 PixelsPerUnitY / 72 (common "default" resolution) = 164,04
So, if the X and the Y resolution differ severely after this calculation, the image will become severly distorted in either direction, also.
Help me: If someone knows of a workaround, meanwhile, I would be grateful to get to know it.
TIA and regards,
too
# Note: I use imagick in text terminals (BASH shell) on up-to-date Linux systems only.