Page 1 of 1

Re: Dithered Edges when converting from PNG to GIF, same problem

Posted: 2008-12-17T12:11:24-07:00
by fmw42

Re: Dithered Edges when converting from PNG to GIF, same problem

Posted: 2008-12-17T22:27:40-07:00
by anthony
Without either color replacement or flood fill is tricky.

Basically you will need to determine what pixels are NOT involved in the anti-aliasing of the edges. Usually that is by floodfill or coor replacement.

If those are NOT posible, especially when involving background colors other than white or black, then you will need a masking method.

For that separate out a mask of the original image, ( -alpha extract ) and resize that
a -threshold 0 of that will then give you the transparency mask of the pixel not involved in anti-aliasing.

Now take the original image flatten it on white (or what ever background color), then resize it in the same way. Now if you re-add the thresholded mask, (using -compose CopyOpacity ) you make the pixels not involved in the anti-alising, transparent.

Here is the command (for a skyblue background)

Code: Select all

convert orig2.png \
  \( -clone 0 -background skyblue -flatten -resize 100x100 \) \
  \( -clone 0 -alpha extract -resize 100x100 -threshold 5% \) \
  -delete 0 -compose CopyOpacity -alpha off -composite \
  result.gif
This works, and should produce an image with a anti-aliased edge blending to a skyblue background. You can use whatever color you like.

NOTE: the threshold is 5% due to the way resize works. A smaller
value than this (unless a "Gaussian" or better still a "Mitchell " filter is enforced, can produce 'ringing effects'. This does not happen if transparency is present as IM would automatically switch to a "Mitchell" filter. For more infor see 'Ringing' Artifacts, in Im examples, Resize page.