How to create animated GIFs using ImageMagick

Create animated GIFs using "burst mode" photos taken with your smartphone.

Credit: Stephen Glasskeys

Burst mode

This tutorial shows how to create animated GIFs using "burst mode" photos taken with a smartphone. Although I used a Lumia 1020 -- running Windows Phone 8.1 OS -- to take my photos, most smartphones sold today support burst mode photography. This group includes the Samsung Galaxy series of phones running Android, as well as newer iPhones running iOS.

So, as long as you can create and save burst mode photos to a folder on your Linux, Mac, or Windows machine, this tutorial should prove useful. But before you proceed to the next step, please ensure you have ImageMagick installed first.

Bursting with photos

Many Windows Phone camera apps allow taking photos in burst mode. For this tutorial, I tested a GIF conversion process that works with the most popular of these apps: Lumia Camera and Nokia Smart Cam.

Lumia photography apps

Both of these apps encapsulate burst mode photos inside a file format known as Nokia Archive (nar). These "nar" files are in reality standard ZIP files containing XML files and a sequence of JPEG (jpg) photo images. Old versions of this format contain only one XML file and one set of photo images. However, the latest version (1.1) contains three XML files, and sets of both high and low resolution images.

I decided to use Lumia Camera to take series of rapid fire photos of my friends' dog named Douglas:

Lumia Camera app taking burst mode photos

Later, I imported the nar file to my computer using Windows Explorer, and changed the extension from .nar to .zip. Then, I extracted the contents of the zip file to an empty folder:

Extracted nar of jpg and XML files

From this group, I removed all low resolution (*_rlv.jpg) images and xml files.

Finally, I used two ImageMagick commands to create the 320x180 animated GIF seen below. Both of the following ImageMagick commands process image files in sequential order. Because Windows Phone also names burst mode files numerically in the order they are created, ImageMagick tools become ideal for creating animated GIFs from nar files and/or other ordered image sets.

mogrify -resize 320 *.jpg 
convert -delay 15 -loop 0 *.jpg douglas.gif
Douglas running

An animated GIF created using ImageMagick

A bit of explanation: First, mogrify resizes all JPEG images in the folder to a width of 320 pixels, preserving aspect ratio. The second command, convert, uses the resized image files to create a new animated GIF with a 15 millisecond delay between frames, cycling indefinitely.

Scripting the process

To make life easier and to automate this process, I've created a Windows batch file and a bash script for Mac OS X and Linux users, naming both cvnar. For those running Windows, you will need the 7-Zip utility installed beforehand in order for the batch file to work.

NOTE: If you uncomment the lines in the "clean up" section at the end of either script, I highly recommend placing your nar files in an empty conversion folder, then changing directory to the same folder before running. This is because both scripts delete all JPG and XML files in the current folder if these lines are uncommented, leaving only the original nar file and new animated GIF.  

Windows batch file
Mac OS X and Linux bash script

Feel free to download either of these scripts from GitHub, here.

This article is published as part of the IDG Contributor Network. Want to Join?

ITWorld DealPost: The best in tech deals and discounts.
Shop Tech Products at Amazon