I did a little investigating using your code there…
it looks like the flag “-layers optimize” is causing the broken look.
$ convert dodo_anim.gif -coalesce -gravity center -background transparent -thumbnail 60x60 -layers optimize dodo1.gif
$ convert dodo_anim.gif -coalesce -gravity center -background transparent -thumbnail 60x60 dodo2.gif
$ convert dodo_anim.gif -coalesce -gravity center -thumbnail 60x60 -layers optimize dodo3.gif
$ convert dodo_anim.gif -coalesce -background transparent -thumbnail 60x60 -layers optimize dodo4.gif
$ convert dodo_anim.gif -gravity center -background transparent -thumbnail 60x60 -layers optimize dodo5.gif
After looking at the output of each trial, I found that “-layers optimize” causes the transparency to fudge up.
The price of removing the switch for this image was only 147B
$ ll dodo*
-rw-r--r-- 1 sigurdur sigurdur 12437 feb 24 15:50 dodo1.gif
-rw-r--r-- 1 sigurdur sigurdur 12584 feb 24 15:51 dodo2.gif
-rw-r--r-- 1 sigurdur sigurdur 12437 feb 24 15:52 dodo3.gif
-rw-r--r-- 1 sigurdur sigurdur 12437 feb 24 15:52 dodo4.gif
-rw-r--r-- 1 sigurdur sigurdur 12437 feb 24 15:52 dodo5.gif
-rw-r----- 1 sigurdur sigurdur 995 feb 24 15:48 dodo_anim.gif
What’s worse is that the emoji is being upscaled to 60x60, not downscaled or the resolution kept.
To make sure you’re only downscaling (not upscaling to 60x60), you can add the >
tag to the command … let me show you how:
$ convert dodo_anim.gif -coalesce -gravity center -background transparent -thumbnail 60x60\> dodo7.gif
$ ll dodo*
-rw-r--r-- 1 sigurdur sigurdur 12437 feb 24 15:50 dodo1.gif
-rw-r--r-- 1 sigurdur sigurdur 12584 feb 24 15:51 dodo2.gif
-rw-r--r-- 1 sigurdur sigurdur 12437 feb 24 15:52 dodo3.gif
-rw-r--r-- 1 sigurdur sigurdur 12437 feb 24 15:52 dodo4.gif
-rw-r--r-- 1 sigurdur sigurdur 12437 feb 24 15:52 dodo5.gif
-rw-r--r-- 1 sigurdur sigurdur 941 feb 24 15:58 dodo6.gif
-rw-r--r-- 1 sigurdur sigurdur 941 feb 24 16:00 dodo7.gif
-rw-r----- 1 sigurdur sigurdur 995 feb 24 15:48 dodo_anim.gif
What about the optimization?
Well, I did a little test on adding the optimization flag to see if the gif would break…
$ convert dodo_anim.gif -coalesce -gravity center -background transparent -thumbnail 60x60\> -layers optimize dodo8.gif
$ ll dodo*
-rw-r--r-- 1 sigurdur sigurdur 12437 feb 24 15:50 dodo1.gif
-rw-r--r-- 1 sigurdur sigurdur 12584 feb 24 15:51 dodo2.gif
-rw-r--r-- 1 sigurdur sigurdur 12437 feb 24 15:52 dodo3.gif
-rw-r--r-- 1 sigurdur sigurdur 12437 feb 24 15:52 dodo4.gif
-rw-r--r-- 1 sigurdur sigurdur 12437 feb 24 15:52 dodo5.gif
-rw-r--r-- 1 sigurdur sigurdur 941 feb 24 15:58 dodo6.gif
-rw-r--r-- 1 sigurdur sigurdur 941 feb 24 16:00 dodo7.gif
-rw-r--r-- 1 sigurdur sigurdur 928 feb 24 16:03 dodo8.gif
-rw-r----- 1 sigurdur sigurdur 995 feb 24 15:48 dodo_anim.gif
Saved 13 B and the image displays properly
So, my recommendation is to add the >
flag on the thumbnail option.
I would have submitted a PR with this fix, but I can’t get this to behave the same way as @Sano in my test environment …