Possible bug: convert from PNG with resize|scale to 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
too
Posts: 2
Joined: 2018-08-26T03:12:24-07:00
Authentication code: 1152

Possible bug: convert from PNG with resize|scale to PNG

Post by too »

[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:

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!
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.
Last edited by too on 2018-08-27T05:33:03-07:00, edited 2 times in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Possible bug: convert from PNG with resize|scale to PNG

Post by snibgo »

This is beyond my knowledge, but for those who can help:

Please say in which version of IM you see this. As this seems to be a feature of writing PNG, your libpng version may also be relevant.

If it worked in a previous version of IM or libpng, please give the versions.
snibgo's IM pages: im.snibgo.com
too
Posts: 2
Joined: 2018-08-26T03:12:24-07:00
Authentication code: 1152

Re: Possible bug: convert from PNG with resize|scale to PNG

Post by too »

Thanks for the hint concerning version information. Ich added these information to the top of my OP.

I don't know if it ever happened in an earlier version or not as there were never wrong scaling issues on my own system or on websites and social networks I used. Rather, in summer 2017 and in spring and summer 2018 different customers pointed these errors out. I was confused to receive these notes. All three customers used some flavour of PS (creative cloud) and were able to fix the issue for every single image I delivered to them by changing something they found in their PS menus ... like "pixel ratio correction" ("Pixel-Seitenverhältnis-Korrektur" in german). I believe this scaling problem appeared on both Windows and Mac systems my customers used.

HTH,
too
Post Reply