Adding a delay to the end of an animated gif

I converted a screen recording to a looping animated gif. It looked and played fine, but I also wanted it to pause for a few seconds at the end before starting the loop again. I couldn’t find an easy way to do this using online tools without increasing the file size of the result.

I eventually figured out how to add the delay using the open-source command-line tool gifsicle. Here is the command:

gifsicle -U original.gif "#0--2" -d200 "#-1" -O2 > with-delay.gif
  • The -U option unoptimizes the input gif so that we can operate on individual frames.
  • -d specifies the delay to use in hundredths of a second.
  • “#0” format specifies a frame number or range of frames. Negative numbers count backwards from the last frame, starting with #-1. So the range from the first to second-to-last frame is #0 to #-2 or “#0–2”.
  • -O2 (capital letter O) directs gifsicle to re-optimize the gif using recommended settings.

In summary, this command unoptimizes (-U) the original gif into its component frames; then says we want a new gif with the first frame through the second-to-last frame (#0–2) unchanged and the last frame (#-1) with a new delay of 2 seconds (200 hundredths of a second); and finally specifies that we want to re-optimize the result (-O2).

Thanks to the gifsicle manual and a reddit user for helpful hints.

One Reply to “Adding a delay to the end of an animated gif”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.