Merge GIFs with gifsicle

By  on  
Merge GIFs

Creating a GIF from a video is fairly simple at this point, as I pointed out in Convert Video to GIF or GIF to Video, but working with multiple GIFs is something many people would like to do.  The top GIF manipulation library for years has been Gifsicle, so I looked toward Gifsicle for merging multiple animated GIF images.

Before you merge your GIFs, however, you'll want to ensure that they're the same size.  Gifsicle has a --crop option which crops images to a given size:

gifsicle --crop 300x300 ....

If you have GIFs of different sizes (i.e. you don't crop), the earlier GIF may show up behind subsequent GIFs, making for a sloppy image.

Additionally you may receive a gifsicle: warning: too many colors, using local colormaps error.  To work around that error, you'll want to add --colors 256 parameter when merge the GIFs.

So let's assume you have GIFs of the same size and you're ready to create your merged GIF.  The following command will achieve the desired result:

gifsicle --crop 370x275 --colors 256 --merge first.gif second.gif -o merged.gif

You can use any number of GIFs and the outcome is a solid, single GIF.  If you're a performance nut, you'll want to optimize the GIF as well!

Gifsicle continues to amaze me and I look forward to using the utility more.  GIFs by nature are mostly for fun these days and Gifsicle makes that easy!

Recent Features

  • By
    Introducing MooTools Templated

    One major problem with creating UI components with the MooTools JavaScript framework is that there isn't a great way of allowing customization of template and ease of node creation. As of today, there are two ways of creating: new Element Madness The first way to create UI-driven...

  • By
    Creating Scrolling Parallax Effects with CSS

    Introduction For quite a long time now websites with the so called "parallax" effect have been really popular. In case you have not heard of this effect, it basically includes different layers of images that are moving in different directions or with different speed. This leads to a...

Incredible Demos

  • By
    MooTools ContextMenu Plugin

    ContextMenu is a highly customizable, compact context menu script written with CSS, XHTML, and the MooTools JavaScript framework. ContextMenu allows you to offer stylish, functional context menus on your website. The XHTML Menu Use a list of menu items with one link per item. The...

  • By
    Create a Quick MooTools Slideshow with Preloading Images

    I've been creating a lot of slideshow posts lately. Why, you ask? Because they help me get chicks. A quick formula for you: The following code snippet will show you how to create a simple slideshow with MooTools; the script will also...

Discussion

  1. That’s pretty neato! The possibilities are infinite (or dare I say OVER 9000)!

  2. Matija

    Gifsicle is fantastic. If you want to know more see http://webstackoflove.com/modifying-loop-flag-for-animated-gif-files/ as I’ve used it for modifying loop flags and batch processing.

    • Whoa, excellent! I was looking to do a post on exactly that but you’ve beaten me to it! Awesome!

  3. Well, TBH i’m not sure where exactly do I add the command lines :/

  4. Via the Terminal app or similar depending on your OS.

  5. NanooGeek

    gifsicle 1.87 Win64 works, and produces a combined output from two looping .gif from skywarn.org (did Not use --crop, since they are larger than the example, and of uniform size). However, the combined gif only loops through the 1st part.

    • NanooGeek

      Aha, one must use the --append flag, instead of --merge.

  6. Dan

    How do you get to the interface so you can actually create the gifs????

  7. Locks

    How would go about merging 100+ gifs in a directory? Does gifsicle work with grep functions?

    • Locks

      In case anyone else was looking for the answer to this question. This can be achieved with:
      gifsicle --colors 256 --merge *.gif -o output.gif

  8. Locks

    Can anyone recommend an alternative to gifsicle that can support merging gifs with greater than 8-bit (256) colour?

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!