28

I have a bunch of png files named as 1.png, 2.png, etc. and I want to create an animated gif image from them all. I haven't been successful in finding a solution for a terminal command that will convert these png files into a single animated gif.

Can someone post some commands that I can try? I have tried "convert" commands but my terminal always says convert is not found even though I have installed ImageMagik.

StanLe
  • 5,037
  • 9
  • 38
  • 41
  • 1
    If you are (fairly) sure `convert` should be somewhere in your system, try [`whereis`](http://superuser.com/questions/40301/which-whereis-differences). – Jongware Nov 24 '13 at 17:41

2 Answers2

46

convert *.png screens.gif

This answer suggested installing convert with brew install ImageMagick.

kilojoules
  • 9,768
  • 18
  • 77
  • 149
ViliusK
  • 11,345
  • 4
  • 67
  • 71
28

ImageMagick's convert command works perfectly for this but you'll want to list the filenames in the correct order. Using *.png will jumble frames if the digits don't have the leading zeros because the ordering is alphabetical:

1.png  10.png  11.png  2.png  3.png  ...

If you use zsh you can simply use a glob qualifier:

convert *.png(n) out.gif

Otherwise you can sort the ls output

convert $(ls *.png | sort -V) out.gif

If your filenames have leading zeros go ahead and use *.png. Note that the default delay between frames is small, so depending on your use case the frame rate might be too quick. To change that use the -delay option, for example:

convert -delay 50 *.png out.gif

This will set FPS to 100/50 = 2 frames per second.

wim
  • 338,267
  • 99
  • 616
  • 750