# Add delay to the final frame of a GIF?

I'd like for there to be a pause during the final frame in my animation, before it loops.

Here's some tweekable starter code:

frames = Import["ExampleData/cellularautomaton.gif"];

Export["~/cellularautomaton.gif", frames, "Interlaced" -> True,
"DisplayDurations" -> Table[0.1, Length[frames]],
"AnimationRepetitions" -> \[Infinity]]


I looked at the docs for .GIF, nothing there on this. Also, I thought of padding the list with repetitions of the last frame, but that is a waste of space, and the GIF mime type supports this.

• I believe the only solution to this is the ugly brute force way: give it a bunch of duplicate copies of the last frame. May 24 '16 at 21:06
• @george2079 has it right, there's no delay-by-frame options.
– ciao
May 24 '16 at 21:13
• having said that, @Karsten7 's answer does work. I don't know how universally that will be supported by different viewers however. May 24 '16 at 21:32
• @george2079 Providing a list as DisplayDuration has worked pretty much since forever. See, e.g., this old post. So there definitely is a delay-by frame option.
– Jens
May 24 '16 at 23:30

You can simply increase the display duration for the last frame.

Export["test.GIF", frames, "Interlaced" -> True,
"DisplayDurations" -> ReplacePart[Table[0.1, Length[frames]], -1 -> 1.0],
"AnimationRepetitions" -> ∞]


Citing the GIF documentation:

• "DisplayDurations"->{d1, d2, ...} specifies the display durations for each frame in an animated GIF. If the list of display durations is shorter than the number of frames, the sequence is repeated as necessary.
• With the default setting "DisplayDurations"-> Automatic, the display time will vary on different viewer applications.
• "All too easy" - I forgot I was using a list!
– M.R.
May 24 '16 at 21:34
• This could be a separate questions, but what about changing the "AnimationDirection" to "ForwardBackward" in the gif? Would I have to double the number of frames or is there an undocumented option?
– M.R.
May 25 '16 at 15:03
• @M.R. AFAIK there is nothing like an "AnimationDirection" for GIFs. It's not part of the file specification and it's not how GIFs work. If you want to create a "ForwardBackward" GIF, you'll have to create a complete "ForwardBackward" list of frames as one loop. If you do so just using Mathematica the file size will probably be twice. However, other tools (e.g. GIMP) can do a much better job optimizing a GIF (for example using combine frames instead of replace frames), which results in much smaller file sizes. May 25 '16 at 17:23
• @M.R. This GIF is Mathematica exported forward (2 KB), this GIF is Mathematica exported forward and backward (4 KB), and this GIF is the forward and backward GIF optimized with GIMP (1 KB). May 25 '16 at 17:47
• Nice! Also seems the minimum display duration is 0.015 second, can you confirm?
– M.R.
May 26 '16 at 3:30