Ignore color information of completely transparent pixels when resizing images #159
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes artifact reported in itgalaxy/favicons#123
Black faint on the edges of opaque areas appears because color information of completely transparent pixels is taken into account during calculation of average color, but these pixels could be of any color. Completely transparent black completely transparent red looks identicall, so it's somewhat a common practice to replace RGB values with 0 or 255 for series of completely transparent pixels. Many encoders do this, (probably) to allow for a better compression.
Two images below illustrate what transparent areas sometimes look like if we make every pixel opaque.
This PR changes both submodules responsible for image resizing in the way that only color data of visible pixels used in average color calculation. Also
fixed incorrect channels value inreduced amount of dupplicated code inResize.prototype.resizeWidthInterpolatedRGBA
method (iwsfg/jimp@65158a9) and/resize.js
And here's a comparison table. 6 images, every transparent pixel of which was painted in black, were scaled down from ~1000x1000 to 200x200 px using every resampling method supported. Then results from before and after patch were glued together for every image. The difference is pretty noticeable
Here's list of images from the table above in their original size: