Create Animated GIF in Linux from Command Line

By | 2011/07/31

Imagemagick can easily make an animated gif from existing images with a simple command. I’ll show you how!


First, install imagemagick:

$ sudo apt-get install imagemagick


Next, gather all of your .jpg images together in a single folder or directory.

If needed, date/name files in a numbered or sequential order. The manor in which they appear listed in your directory is the order they will appear in the animated GIF!

tmp-file-browser_140
Next, resize your .jpg images to a smaller size, such as 640×480 by using the following command:

$ mogrify -resize 640x480 *.jpg


And finally, issue the command below to create an animated gif of your jpg images.

Increase the delay time for a longer transition between images. Tack loop 0 will loop your GIF indefinitely. Tack loop 3 would loop three times, for example.

$ convert -delay 20 -loop 0 *.jpg myimage.gif


Done!

25 thoughts on “Create Animated GIF in Linux from Command Line

  1. Jordan

    Thanks for the tip! Was looking for an easier way than using layers in the GIMP… this was perfect!

    Reply
  2. Drubie

    Thanks dude! I always need a quick reminder of the command names and flags. Keep up the good work!

    Reply
  3. David

    Wow! Why didn’t anyone tell me about this months ago? I had no idea it was so easy!
    Thanks a million!

    Reply
  4. Joel

    Thank you very much. This was exactly what I was looking for.

    Reply
  5. plantpark

    convert.im6: memory allocation failed `image.gif’ What’s the problem? Only 20 jpgs, and 320×240.awaiting for your help,thanks

    Reply
    1. scott Post author

      Yeah it ran out of memory to generate that final gif.

      Is this a virtual machine you can allocate more ram to?

      Reply
  6. Marcos

    Muchas gracias por el post. Quería hacer un gif con 30 imagenes y necesitaba hacerlo de la línea de comandos 😀 , gracias!!.

    Reply
  7. Leo

    Hi Scott,
    Let me suggest you add a warning to the mogrify command, about the images being replaced, just in case someone doesn’t realize before it’s too late 😉

    Thanks for the quick tips!

    Reply
    1. Colin

      Yes, good point, it is best to copy/paste the images you want in the GIF into a temporary folder and run the resize command there, then the originals are never changed..

      Reply
  8. spoulin

    Hi

    I would like to do this with only let’s say only the 30 lasts added pictures in a folder… how can I do this ?? :-/

    thanks.

    Reply
    1. diego

      Please, read “man ls” before ask.
      Everything can do it reading this.

      But, if you lazy like me:

      for file in $( ls -1rt|tail -n 30); do yourcommand $file; done

      Reply
  9. Kurt Sanger

    I had made a few using layers in gimp and exporting to animated gif. That method was getting tedious. Looks like I need ImageMagic. Love the resize command too as to do that automatically in gimp I wrote a gimp script-fu script. ImageMagick is much simpler.

    Thanks

    Reply
  10. carolinareaperapostle

    Nice and informative post!

    As an added bonus, prior to creating your animated gif you might want to add some text to the individual image files. Try using the “convert” command as follows:

    convert 000001.jpg -fill white -font /path/to/your/font.ttf -fill white -gravity South -pointsize 40 -annotate +0+5 ‘ TEXT TO PUT IN IMAGE ‘ ../newfilename.jpg

    The result will put the text TEXT TO PUT IN IMAGE at the bottom of your converted image. The new image will be found in the directory immediately below the one you ran the command from. Useful for creating animated memes. I’d suggest using the ‘Impact’ font.

    Do this for each of the images in your loop prior to creating the gif. Have fun!

    Reply
  11. John Jackson

    Thanks very much.
    I have used this many times over the years, only just got round to thanking You.
    Best on the net.

    Reply

Leave a Reply

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

Notify me of followup comments via e-mail. You can also subscribe without commenting.