Page 1 of 1

Anti-Aliasing border for transparent GIF animation

Posted: 2014-01-04T11:56:54-07:00
by viky
Hi all,
I have a PNG image (clock.png) which contains 59 frames and I want to build a GIF animation. For this, I use the following:

Code: Select all

E:\ImageMagick\convert.exe -delay 1x25 clock.png -crop 20x20 +repage clock.gif
Everything is OK, except the clock border:
Image
If I understand correctly, to correct this "bug" I need to enable Anti-Aliasing or smooth options — I tries several options, but without any success. After thorough testing, I found a method which allow to correct the aliasing bug:

Code: Select all

E:\ImageMagick\convert.exe -delay 1x25 clock.png -crop 20x20 +repage -bordercolor "#ebebeb" -border 0x0 clock.bad_bg.gif
The result of command above:
Image
It looks exactly what I need, but, this image looks awfully on another background colors (for examples look here). After countless attempts, I decided to ask for aid. So, please, help me to build a perfect animation with smooth borders and transparent background.

Any help will really appreciated.
Thank you!


ABOUT MY SYSTEM:
ImageMagick Version: 6.8.8-1 Q16 x86 2013-12-25 (Portable Win32 static at 16 bits-per-pixel)
Operating System: Windows 7 Home Premium (SP1)

Re: Anti-Aliasing border for transparent GIF animation

Posted: 2014-01-04T13:19:16-07:00
by fmw42
I am not sure you can do what you want. The problem is that gif only supports binary transparency (on or off and thus no antialiasing). That is why you see the jagged boundary of the clock. When you add the right border color it may disappear, but that only works with one border color. What is needed is to have 8-bit transparency such as with PNG so that you can antialias the transparency. But PNG does not support animations. There is a MNG png-like format, but no one uses it. There is an APNG format, which is a more common png-like animation format, but IM does not support that. So you are unfortunately stuck between a rock and a hard place for now with IM.


You can improve your results by antialias the border of each image by slightly blurring the alpha channel and then flattening against a color background and then creating the gif animation. But then you need to do that for every background color you want to use. see http://www.imagemagick.org/Usage/blur/#feathering and http://www.fmwconcepts.com/imagemagick/ ... composite2





I will defer to any other suggestions on this.

Re: Anti-Aliasing border for transparent GIF animation

Posted: 2014-01-04T13:34:58-07:00
by snibgo
I have little experience of GIF animations, but I agree with fmw. An "animation with smooth borders and transparent background" isn't possible in GIF because alpha is binary.

The best solution is probably to build a separate GIF for each possible background. If any background is possible, then create it on the fly.

Re: Anti-Aliasing border for transparent GIF animation

Posted: 2014-01-04T13:52:10-07:00
by viky
@fmw42, @snibgo,
Basically, I knew something was wrong with my problem, because I could not find anything useful in the documentation. Anyway, thank you very much for your replies.

I also thought about to create images on the fly, but the problem is that I have an “infinite” number of background colors and, I think it would be a bad solution to this problem. And now, I do not know how to be...

If I will find the optimal solution, certainly I'll write about it here.
But in the meantime, I am waiting for Christmas miracles :)

Re: Anti-Aliasing border for transparent GIF animation

Posted: 2014-01-04T14:20:29-07:00
by snibgo
Another possibility wold be to create, say, 64 GIFs (=4x4x4) with 64 backgrounds, where pixels of exactly that background are made transparent. Then when you have one of the infinite possibilities, use the closest GIF you have. You would get anti-aliasing around the clock, but a non-aliased boundary between the 1-of-64 and 1-of-infinite. This would be hardly noticeable. If it isn't good enough, you might create 5x5x5 GIFs or ...

Re: Anti-Aliasing border for transparent GIF animation

Posted: 2014-01-04T14:25:25-07:00
by viky
snibgo, thank you very much! This is really interesting and useful idea.

Re: Anti-Aliasing border for transparent GIF animation

Posted: 2014-01-05T00:13:18-07:00
by fmw42

Re: Anti-Aliasing border for transparent GIF animation

Posted: 2014-01-05T00:27:18-07:00
by viky
@fmw42,
Thank you for useful links. But, before posting my question on the forum, I already tested/checked other formats — the only cross-browser and cross-platform format (without any additional software) is GIF (this is why I cannot use these or other formats rather than it).