Assemble Photos into a GIF Animation or a Slideshow with ImageMagick

Animated GIFs are not only good for sharing funny cat videos. They can also come in rather handy when you want to whip up a quick-and-dirty slideshow that can be viewed on any platform or create a timelapse animation from a sequence of images with a minimum of effort.

Generating animated GIFs can be done using ImageMagick and jhead. To install these tools on Debian and Ubuntu, run the sudo install imagemagick jhead command. If you happen to use openSUSE, run the sudo zypper in ImageMagick jhead command.

In the terminal, switch to the directory containing the photos you want to assemble into an animated GIF, and run the following command:

jhead -n%Y%m%d-%H%M%S *.JPG

This renames the photos using their date and time data to ensure the correct image sequence. Since there is little point in turning full-resolution photos into an animated GIF, resize the source images:

mogrify -resize 800x *.JPG

Generating an animated GIF then is a matter of running the following command:

convert -delay 120 -loop 0 *.JPG foo.gif

The delay parameter specifies the delay between frames in milliseconds, while the loop parameter determines how many times the animation runs (the 0 value will run the loop infinitely).

To automate the process of generating an animated GIF, add the following function to the ~/.bashrc file:

if [ -x "$(command -v mogrify)" ] ; then
  function gif() {
    mogrify -resize "$dimension"x *."$ext"
    convert -delay "$delay" -loop 0 *"$ext" "$output"

Next time you want to transform a set of photos into an animated GIF, switch to the directory with the photos, and run the gif command. To overrride the default settings, specify the required parameters, for example:

gif jpeg 1600 90 foo-big.gif 180

This is an excerpt from the Linux Photography book. Get your copy here.

Tech writer covering Linux and open source software

Tagged with: , , ,
Posted in Open Source, Photography, Software

Recipes for automated and streamlined photographic workflow on Linux

Use digiKam? Get this book!

Practical advice for nighttime photography

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

%d bloggers like this: