Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to compress animated GIFs using ImageMagick, without using Gifsicle

So my web host won't install gifsicle on their shared servers, so I'm stuck with ImageMagick. I want to compress the images like it is here: https://pornel.net/lossygif how can I do that without using gifsicle; using only ImageMagick?

Right now my exec() command goes like:

exec("convert $animation -coalesce -gravity SouthWest  -geometry +0+0 null: $watermark -layers composite -layers optimize $animation");

and the watermarked GIF barely compresses, and sometimes it even gets larger. How could I solve this issue?

like image 319
imjerdev Avatar asked Jul 18 '14 07:07

imjerdev


1 Answers

I had success with ImageMagick's Mogrify: https://www.imagemagick.org/script/mogrify.php

After you generate a large gif, you can make it smaller.

My command looked like:

mogrify -layers 'optimize' -fuzz 7% mygif.gif

The -layers option optimized any layers in your gif

The biggest space savings comes from the -fuzz option, which specifies that colors within a certain tolerance can be considered the same color.

My several second gifs went from 3 MB to a few hundred kb.

like image 53
dcoffey3296 Avatar answered Oct 06 '22 19:10

dcoffey3296