Page 1 of 1
Aliased/jagged edges when creating animated gif with transparent background
Posted: 2017-06-08T10:57:58-07:00
by starjet
(Using version ImageMagick 7.0.5-10 Q16 x64 on Windows 10, convert.exe via command line)
I have a small batch of PNG files with transparent background that I want made into an animated GIF file. I'll provide them here for reference:
https://files.catbox.moe/r1qu5c.rar
Now after using
Code: Select all
convert -dispose previous *.png test.gif
I get a GIF file that works as expected, but on some backgrounds appears highly aliased. On googling for solutions I have read things that implies that it's natural for GIF. However, I can do this in Photoshop without the result appearing aliased. Comparison here:
http://imgur.com/a/FrIdk
Unfortunately, Photoshop is not an option for me as I need this to be doable via command line. If somebody could help me out, I'd be really grateful.
Re: Aliased/jagged edges when creating animated gif with transparent background
Posted: 2017-06-08T13:30:31-07:00
by fmw42
Gif does not support 8-bit transparency. It only allows binary transparency. So that is why you get the noticeable aliasing in the gif output. There is nothing that can be done about as far as I know other than to create your animations as video (mpeg, etc) and not use gif animation. ImageMagick supports MPNG, but not APNG for animation, I believe. But MPNG is not very portable.
Re: Aliased/jagged edges when creating animated gif with transparent background
Posted: 2017-06-08T19:09:36-07:00
by starjet
fmw42 wrote: ↑2017-06-08T13:30:31-07:00
Gif does not support 8-bit transparency. It only allows binary transparency. So that is why you get the noticeable aliasing in the gif output. There is nothing that can be done about as far as I know other than to create your animations as video (mpeg, etc) and not use gif animation. ImageMagick supports MPNG, but not APNG for animation, I believe. But MPNG is not very portable.
As I mentioned, I read explanations along these lines before coming here. However, both files in my comparsion are gif. The one made with Photoshop doesn't have this issue.
Re: Aliased/jagged edges when creating animated gif with transparent background
Posted: 2017-06-08T19:11:56-07:00
by fmw42
Post both files to some free hosting service and put the URLs here so we can examine them. Also post your exact IM code or better the equivalent as a command line.
EDIT: sorry, I did not see you had posted that above.
Re: Aliased/jagged edges when creating animated gif with transparent background
Posted: 2017-06-08T19:31:52-07:00
by fmw42
Sorry, I tested your data and get the expected aliasing due to gif binary transparency. If you are willing to replace the transparency with some color, then each file can be flattened against the background color and the gif animation created from them, which should not have aliased edges, since there is no transparency.
Unfortunately, I do not know how you created your animation in Photoshop, so cannot comment on how they are able to avoid that issue. Nor do I know enough about GIF transparency. Perhaps some other tools can created 8-bit gif transparency, but IM will not, to my understanding.
glennrp is the GIF expert here. Perhaps he can comment further or correct my understanding.
Re: Aliased/jagged edges when creating animated gif with transparent background
Posted: 2017-06-08T19:40:47-07:00
by fmw42
Re: Aliased/jagged edges when creating animated gif with transparent background
Posted: 2017-06-08T19:47:24-07:00
by starjet
I simply imported all the frames in as layers and then used the "make frames from layers" feature, on Photoshop CS3.
Thank you for the information on how Photoshop does it. I'll try looking into other options.
Re: Aliased/jagged edges when creating animated gif with transparent background
Posted: 2017-06-08T20:17:32-07:00
by fmw42
If I flatten each PNG against a black background, then make the animation, it shows no aliasing as I mentioned above. I chose black since the color under your transparency in the PNG was black, so any antialiasing was against a black background. However, I tried a white background and that worked fine also. So the color probably does not matter.
Here I use subshell processing in Unix (Mac OS X) to avoid having to save each new PNG image before making the animation. I called your folder of images, data. Curious why there is no imagename001.png?
Code: Select all
cd
cd desktop/data
list=`ls *.png`
echo "$list"
( for img in $list; do
convert $img -background black -flatten miff:-
done ) | convert -dispose previous -delay 10 - -layers optimize animation.gif
Re: Aliased/jagged edges when creating animated gif with transparent background
Posted: 2017-06-08T20:31:20-07:00
by starjet
Thanks again. This definitely works. However, my idea is to retain transparency, so this is a little less than ideal. I'm looking into some other ways to go about this now, so I'll report back if there's any progress, just in case someone else might also want to do something like this.
Also, the files were originally 001 to 017, and 001 was actually the last frame, so I just renamed it to 018 for convenience.
Re: Aliased/jagged edges when creating animated gif with transparent background
Posted: 2017-06-09T00:10:17-07:00
by snibgo
As Fred says, gif alpha is binary (either 0 or 100%), but the input PNG files have values across the full range. Some experimentation on just the first frame shows that PS thresholds alpha at 50%, and IM doesn't, so:
Code: Select all
-channel A -threshold 50% +channel
Re: Aliased/jagged edges when creating animated gif with transparent background
Posted: 2017-06-09T09:13:39-07:00
by fmw42
snibgo wrote: ↑2017-06-09T00:10:17-07:00
As Fred says, gif alpha is binary (either 0 or 100%), but the input PNG files have values across the full range. Some experimentation on just the first frame shows that PS thresholds alpha at 50%, and IM doesn't, so:
Code: Select all
-channel A -threshold 50% +channel
That is a good point. But I tried it in my scripting and it does not seem to make much difference. I still cannot figure out exactly how PS matte works to mitigate aliasing for transparent images