Hack4.Animate Images

Hack 4. Animate Images

Pass arguments to the convert tool to turn a directory of images into an animated GIFall without opening a GUI tool.

The convert utility has plenty of tricks up its sleeve. One of the tricks is the simple conversion of a series of images into a single animated GIF file. Since convert can handle a large variety of image formats, you don't even need to start out with a directory of GIF-only images.

When it comes to image processing, convert does a lot of the heavy lifting on its own. In fact, the only option you need to concern yourself with is the -delay option, which specifies, in milliseconds, how long to wait between each image change. You can use the animate tool from the ImageMagick suite to test your animation. To see what your animation would look like with a one-second delay on a directory full of GIF images, type:

 $ animate -delay 100 *.gif 

This command displays each image in alphabetical order, one after the other. If you want to display them in a different order, specify the images in that order on the command line. Once you are satisfied with your delay rate you can use the same number with the convert command. To convert a directory of GIF files into a single animated GIF with one second between frames, type:

 $ convert -delay 100 *.gif  animated.gif   

Because I used a file glob here, I assumed the images were in alphabetical sequence. If they aren't in order, either specify each file on the command line (with the animated GIF specified last) or rename the files so that they are sequential. To see your newly created animated GIF, type:

 $ display animated.gif 

This tool can be particularly useful if you take periodic images with a webcam, even if they are JPEGs. Simply put all the webcam images you want to animate into a directory and type:

 $ convert -delay 100 *.jpg  animated.gif  

Replace *.jpg with a file glob that matches your image format.

Linux Multimedia Hacks
Linux Multimedia Hacks
ISBN: 596100760
Year: 2005
Pages: 156

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net