How to set animated GIFs to loop playback

Tadashi Shigeoka ·  Mon, August 29, 2016

I wondered why animated GIF files play endlessly when opened with spacebar in macOS Finder, but only play once when opened in a browser, so I looked into it.

There was a similar question on Stack Overflow with an answer saying “It’s defined in the gif file, so you need to edit to enable endless animation loops,” and I was oddly impressed thinking “Oh, of course that’s right.”

For editing gif files, I used Gifsicle, a Command-Line Animated GIFs tool.

Installing gifsicle

brew install gifsicle

Loop setting methods

Infinite loop

To set the loop count of original.gif to infinite, just run the gifsicle command with the -l, —loopcount option.

gifsicle --loopcount original.gif > output.gif
gifsicle -l original.gif > out.gif

You can also overwrite original.gif by adding the -b, —batch option.

gifsicle --batch --loopcount original.gif
gifsicle -bl original.gif

Specify loop count

When you want to specify the loop count of original.gif, you can set it with the -l=N, —loopcount=N option.

For example, for 2 loops:

gifsicle --loopcount=2 original.gif > out.gif
gifsicle -l=2 original.gif > out.gif

can be used. In this case, the animated gif plays a total of 3 times.

That’s all from the field about wanting to make animated gifs loop playback.

That’s all from the Gemba.