Skip to content

Instantly share code, notes, and snippets.

@artwilton
Last active April 13, 2021 04:15
Show Gist options
  • Save artwilton/119ef07176f913ebeca1e6fe3b1452cb to your computer and use it in GitHub Desktop.
Save artwilton/119ef07176f913ebeca1e6fe3b1452cb to your computer and use it in GitHub Desktop.

Compressing GIFs

Converting file to a GIF and compressing using imagemagick and gifsicle:

convert -delay 4 <source> -loop 0 +dither -layers OptimizePlus "${@:3}" gif:- | gifsicle -O3 --dither --lossy=30 --resize-width 640 -V -o <output>.gif


Parameters explained:

For a 24fps or 25fps source use -delay 4

For a 30fps source use -delay 3

Replace <source> with the path for your video or GIF file.

-loop 0 will loop the GIF an infinite number of times, feel free to change this to 1 to only loops once, or any number of times you want your GIF to loop for.

--lossy=30 is used to determine the amount of compression. You'll need to play around with this to find a balance of quality and file size. The range is from 0 to 100 for less or more compression respectively.

--resize-width 640 determines the final width of the GIF. Again this will need to be changed depending on your source, but for a typical 16:9 aspect ration GIF, I find 640 to be the minimum width that still retains quality.

Replace <output> with the path and filename of the GIF you will be exporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment