IDL routine to make an animated GIF

Written by Eric Weeks, send questions to <weeks(at)physics.emory.edu>

Lab Home -- People -- Experimental facilities -- Publications -- Experimental pictures -- Links

Here's an explanation of making a black & white animated GIF movie. I recommend you don't put the animated GIFs directly on a web page; rather, have a non-animated image that someone can click on to load in the animated GIF. There are two good reasons for this: (1) The animated GIF files can be very big (1 MB or more sometimes) and thus would make your page load extremely slowly, and (2) some people don't like animated GIFs and you don't want someone looking at your research page to get annoyed at you and stop reading.

Note that all of this was developed for Linux; the key routine is the public domain utility gifsicle. Apparently there is a Windows version of this, from the same location, but I have not tested the IDL routines below in Windows. Also, the IDL routine I wrote calls some built-in Linux functions to handle GIF files as the latest versions of IDL don't support GIF.

  1. Get an IDL variable containing your movie. In other words:
          IDL> help,a
          A               BYTE      = Array[320, 240, 100]
    
    So, "a" is a 100 image stack of 320 x 240 pixel images.

  2. Run this command in IDL:
          IDL> bw_animgif,a,'filename'
    
    The filename is arbitrary. Click here to download bw_animgif.pro. You'll also need writetifs.pro and int2ext2.pro. Weeks Lab people, these are already installed.

  3. That command will print out the message:
              run gifsicle command:
              $gifsicle -lforever --colors 256 *.gif > anim.gif
    
    Just cut and paste that 2nd line into your IDL window. This makes a file "anim.gif" which is the animated GIF. You can call it something else besides anim.gif. As a byproduct, you will also have created a bunch of files called filename0001.gif, filename0002.gif -- you can often grab one of these to use as your linking image on your main web page. In other words, your HTML code will be something like:
          <a href="my_anim.gif"><img src="filename0001.gif"></a>
    
    so thus you'll have a still image which links to your movie. You may want to remove the temporary files when you're done (all the rest of the filename0003.gif type files).

  4. You can also do other things to your IDL variable, of course, before you write it out:
           IDL> b=bytscl(a(0:99,20:39,*))
           IDL> c = small(b)
           IDL> bw_animgif,c,'movie'
    
    This would create a contrast-enhanced cropped movie, with the 'small' command making it half-size. I did something like this to make these movies here. Click here to download small.pro.

  5. The main work in making the animated GIF is done by the unix utility "gifsicle". It has a bunch of options, click here to learn more about it -- includes complete documentation.

Let me know if you have any questions. At some point I will write a routine that does animated GIFs in color and post instructions here.
--Eric