25

I have some .png files named '_tmp*.png' and I want to convert them into a gif file by the convert command with imagemagick. So i could use

convert -delay 20 _tmp*.png result.gif

However I want the last frame to hold for a while on screen so that one can see the ending of the animation more clearly. Say, I want the last frame to last for 3 seconds while keeping the delay time for the other frames not changed. I studied the document for the convert command but it seems it does not have such a choice.

So how can I do this with the convert command?

1 Answers1

43

You can do it like this:

convert -delay 40 {1..9}.png -delay 300 10.png -delay 40 {11..14}.png animated.gif 

enter image description here

Basically, you set the delay just before the image you want it to affect and it stays set until you change it.

If you want to set a variable delay, so that the first (i.e. black here) and the last frame (i.e. yellow here) are displayed longer, you can do this:

convert -size 300x200 xc:black xc:red xc:lime xc:blue xc:cyan xc:magenta xc:yellow -set delay '%[fx:t==(n-1) || t==0 ? 400 : 40]' result.gif

enter image description here

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • 1
    Serchell: Thanks! –  Oct 22 '16 at 15:58
  • But my images files are numbered like _tmp%03d.png where the numer ranges from 0 to N, N depends on the program's input, How can I do this in this case? –  Oct 22 '16 at 16:03
  • Assuming you know `N`, use `convert -delay 40 -delay 300 result.gif` – Mark Setchell Oct 22 '16 at 16:11
  • I want to call convert command in a python script, so I have to write the convert command as a string, like –  Oct 22 '16 at 16:15
  • like `subprocess.call(['convert', '-delay', '40', '{1...N}.png'] ......)` –  Oct 22 '16 at 16:17
  • Sorry, I don't know Python, Maybe something like this.. http://stackoverflow.com/a/19683794/2836621 or this http://stackoverflow.com/a/30071309/2836621 – Mark Setchell Oct 22 '16 at 16:23
  • 1
    I'm running this on Windows10. With this: `magick convert -delay 40 {1..11}.png -delay 3000 12.png logo.gif` I only get the last frame in the gif. Syntax `{1..11}.png` does not seem to work. – Fuczak Jan 08 '21 at 20:16
  • 1
    In your case you can also use `convert -delay 40 *.png -delay 2960 12.png logo.gif`. – Yonatan N Oct 11 '22 at 06:35