{"id":2408,"date":"2018-10-08T13:02:43","date_gmt":"2018-10-08T20:02:43","guid":{"rendered":"http:\/\/www.robinstewart.com\/blog\/?p=2408"},"modified":"2018-10-08T13:02:43","modified_gmt":"2018-10-08T20:02:43","slug":"adding-a-delay-to-the-end-of-an-animated-gif","status":"publish","type":"post","link":"https:\/\/www.robinstewart.com\/blog\/2018\/10\/adding-a-delay-to-the-end-of-an-animated-gif\/","title":{"rendered":"Adding a delay to the end of an animated gif"},"content":{"rendered":"<p>I <a href=\"https:\/\/ezgif.com\">converted<\/a> 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&#8217;t find an easy way to do this using online tools without increasing the file size of the result.<\/p>\n<p>I eventually figured out how to add the delay using the open-source command-line tool\u00a0<a href=\"http:\/\/www.lcdf.org\/gifsicle\/\">gifsicle<\/a>. Here is the command:<\/p>\n<pre>gifsicle -U original.gif \"#0--2\" -d200 \"#-1\" -O2 &gt; with-delay.gif<\/pre>\n<ul>\n<li>The <strong>-U<\/strong> option unoptimizes the input gif so that we can operate on individual frames.<\/li>\n<li><strong>-d<\/strong> specifies the delay to use in hundredths of a second.<\/li>\n<li><strong>&#8220;#0&#8221;<\/strong>\u00a0format 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 &#8220;#0&#8211;2&#8221;.<\/li>\n<li><strong>-O2<\/strong>\u00a0(capital letter O) directs gifsicle to re-optimize the gif using recommended settings.<\/li>\n<\/ul>\n<p>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&#8211;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).<\/p>\n<p>Thanks to the <a href=\"https:\/\/www.lcdf.org\/gifsicle\/man.html\">gifsicle manual<\/a> and a <a href=\"https:\/\/www.reddit.com\/r\/GIFCreators\/comments\/16szvx\/how_to_adjust_the_delay_of_an_individual_frame_of\/\">reddit user<\/a> for helpful hints.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;t find an easy way to do this using online tools without increasing the file size of the result. I &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.robinstewart.com\/blog\/2018\/10\/adding-a-delay-to-the-end-of-an-animated-gif\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Adding a delay to the end of an animated gif&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.robinstewart.com\/blog\/wp-json\/wp\/v2\/posts\/2408"}],"collection":[{"href":"https:\/\/www.robinstewart.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.robinstewart.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.robinstewart.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.robinstewart.com\/blog\/wp-json\/wp\/v2\/comments?post=2408"}],"version-history":[{"count":9,"href":"https:\/\/www.robinstewart.com\/blog\/wp-json\/wp\/v2\/posts\/2408\/revisions"}],"predecessor-version":[{"id":2417,"href":"https:\/\/www.robinstewart.com\/blog\/wp-json\/wp\/v2\/posts\/2408\/revisions\/2417"}],"wp:attachment":[{"href":"https:\/\/www.robinstewart.com\/blog\/wp-json\/wp\/v2\/media?parent=2408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.robinstewart.com\/blog\/wp-json\/wp\/v2\/categories?post=2408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.robinstewart.com\/blog\/wp-json\/wp\/v2\/tags?post=2408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}