Page 1 of 1

potential bug in PNG resize 50%

Posted: 2010-12-03T20:55:30-07:00
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

Re: potential bug in PNG resize 50%

Posted: 2010-12-05T18:46:48-07:00
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

Re: potential bug in PNG resize 50%

Posted: 2010-12-05T18:52:59-07:00
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?

Re: potential bug in PNG resize 50%

Posted: 2010-12-05T19:12:23-07:00
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!