How to Create and Edit Animated GIFs from the Command Line in Ubuntu

How to Record Linux Desktop and Create Animated GIF Out of it Using Silentcast

Animated GIFs have become really popular in the past few years, and their popularity is growing with each passing day. Don’t agree? Think about this: over a whopping 23 million GIFs are posted to Tumblr every day. So clearly there’s an audience for this image format.

Does that entice you to create GIFs? If yes, you’ll be glad to know that there are various GUI-based GIF editors that work on different OS platforms. However, if you are on Linux and looking for a command line tool for this job, look no further as we will be discussing Gifsicle – a tool that lets you easily play with animated GIFs.

Note: version 1.78 of Gifsicle was used for all examples mentioned in this article.


Gifsicle is a command line tool for creating, editing, and getting information about GIF images and animations. According to the tool’s official web page, Gifsicle offers several features, including image optimization as well as control over interlacing, comments, looping, and transparency. It “creates well-behaved GIFs: removes redundant colors, only uses local color tables if it absolutely has to (local color tables waste space and can cause viewing artifacts), etc.

Download and Installation

On Ubuntu (as well as other Debian-based systems), you can easily download and install the Gifsicle tool using the following command:

Alternatively you can also build it from scratch using its source code or use a pre-built binary – both are available for download from the tool’s official web page.

Create Animated GIF with Gifsicle

Suppose you have a bunch of jpg files and want to create an animated gif file out of them. Here’s how to do it:

Since the gifsicle command works only on gif files, you’ll first have to convert all the .jpg files into .gif format by using the convert command:

If the number of jpg files is large, you can use the following command to convert all of them:

Once the conversion from jpg to gif is done, the general command to combine individual gifs into a final animated one is as follows:

In the above command the “speed of animation” can be set using the --delay flag, while the “number of times to loop” can be set using the --loopcount flag.

For example, I had the following group of jpg images.


The following is the command I used to produce an animated gif out of the above images:

And here’s the out.gif.


Please note that the value of --delay represents the delay between frames in hundredths of a second. Also, I used “forever” as a value to the --loopcount flag. This is to make sure that the animation doesn’t stop. You can use any integer value if you want the animation to be restricted to that number of counts.

Extract Individual Frames

Gifsicle also allows you to easily extract individual frames from an animated gif. Here’s an example of how I did it:

The command above extracted the first frame from the animated out.gif. I just kept changing the integer value following “#” and the output file name and was able to extract all the frames from out.gif.

If the number of frames in the animated gif is quite high, and you want to extract all of them, then – quite understandably – it’ll be impractical to run the above command again and again manually. In that case you can run the command in a loop from a shell script.

Another thing worth mentioning here is that you can also use negative values with “#.” Negative values refer to frames from the end. For example, “#-1” will bring you the last frame.

Edit Animated GIF

With Gifsicle you can also easily edit animated GIFs. For example, the following command creates a new “out.gif” which is nothing but the old “out.gif” with its first frame replaced with the merge of “a.gif” and “b.gif”:

Similarly, you can use the --delete flag to delete frames. For example, the following command deletes the first frame of “out.gif” with the resultant gif being “out-new.gif”:

Not only can you delete and replace, but you can also add new frames to an animated GIF. For example, the --append lets you add frames towards the end of an animated gif. Here’s an example:

The command above will append the “a.gif” frame to the animated “out-new.gif” and produce the animated “out-new-appended.gif” as output.

You can also use the --insert-before flag to add a frame (or multiple frames) anywhere in an existing animated gif.

Image Transformation

Gifsicle also offers some image transformation options. For example, you can use the tool to resize gif images. You can use the --resize [width]x[height] flag to resize your gif image to a particular width and height. From the command’s man page: “Either width or height may be an underscore ‘_’. If the argument is widthx_, then the output GIF is scaled to width pixels wide without changing its aspect ratio.

Here’s how I performed a resize operation on “out.gif”:


The above command produced a file named “out-resize.gif” which was nothing but a resized “out.gif” with 150px width.


Gifsicle may not be a very popular GIF creating/editing tool, but it’s certainly a very useful one. And let me make it clear that whatever we’ve discussed here is just a tip of the iceberg, as the tool offers a plethora of features/options. I thing it’s worth giving a try – learn more about it here.

Himanshu Arora Himanshu Arora

Himanshu Arora is a freelance technical writer by profession but a software programmer and Linux researcher at heart. He covers software tutorials, reviews, tips/tricks, and more. Some of his articles have been featured on IBM developerworks, ComputerWorld, and in Linux Journal.

One comment

  1. Fun article! Please keep them coming.

    Recently, I’ve been playing around with some of the fun things you can do on the command line. Came across things like cmatrix, sl (steam locomotive), screenfetch, espeak, cowsay/cowthink (with redirection, easy to incorporate into txt files). Installed them all. Funny… my entire search for fun things to do on the command line started when I came across an easter egg: “apt-get moo”

    Recently I was trying to get VT animations to play on the terminal. Eventually I came across (a perl script at and run it as: perl ./ filename.vt (works very well as the script slows down the animation to 9,600 baud speeds).

    Would love to find other ways to not only display VT files but also view color ANSI files (popular during the BBS days). I use to have multiple solutions for ANS Files under DOS (from small TSR ANSI drivers to small binaries).

Comments are closed.