potential bug in PNG resize 50%

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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

potential bug in PNG resize 50%

Post by fmw42 »

IM 6.6.6.2 Q16 (hdri) Mac OSX Tiger.

Resizing the png seems to make the background behind the transparent areas turn black.

See viewtopic.php?f=1&t=17597&start=15#p66287
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: potential bug in PNG resize 50%

Post by anthony »

This is NOT a bug.

Fully-transparent colors are undefined, and mathematically they are black. Many operators that handly transparency will set fully transparent colors to black, as that is the way their internal mathematics work.

Resize, Scale, Distort, Blur (with -channel RBA), Morphology (by default with 'Alpha Sync'), etc etc will all reset fully-transparent to black.

If you like to set this 'undefined fully-transparent color' to somethign else use -alpha background.
http://www.imagemagick.org/Usage/basics ... background
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: potential bug in PNG resize 50%

Post by fmw42 »

Thanks for the clarification. But why can it not just resize the rgb channels and the alpha channel without setting the background color. Is that just the convention or is there some other reason that it is not just left alone without resetting to some background color?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: potential bug in PNG resize 50%

Post by anthony »

It is the filter (convolution) that is used that does this, but also composition does it for the same reason.

Basically to ensure that transparent colors does not contribute to the final result, and that semi-transparent colors only contribute a smaller weight to the result, the color channels are multiplied by the alpha channel.

That means of course that if all the colors are fully-transparent the result of the filter, covolution or composition is 0 or black.

If this alpha channel weighting is not done you end up with halo effects, such as demonstrated by the old boug reports...
Resize halo
http://www.imagemagick.org/Usage/bugs/resize_halo/
Blur transparency
http://www.imagemagick.org/Usage/bugs/blur_trans/
Blur really should be changed to do alpha channel sync by default! Just as morphology convolution does, probably by having it use morphology!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply