to_gif: A Bash Script for Easy JPG to GIF Conversion

When taking pictures of moving objects or scenes it would often be awesome to convert them into an animated gif. Unless you used a tripod you will still have slight camera movements and shifts which are then visible in the gif. There is a geekoverdose post which describes how to use the hugin commandline-interface for image alignment and imagemagick for gif creation. We will use this basics and build our own script on top of them (script to download here).

A boat in Croatia as example for aligned gifs.

Example image.

We enhanced geekoverdoses approach by:

  • Encapsulation in a shell script, adding parameter parsing
  • Adding rotation detection so the initial image rotation remains

This changes result in two additional dependencies which are gifsicle (for gif rotation) and exiv2 (for rotation-state information). Therefore we included a simple dependency check showing the following message if successful:

user@computer:/my/path$ IMG*.jpg
All dependencies found.

And this one if not successful:

user@computer:/my/path$ IMG*.jpg
Not all dependencies found, check if the following packages are installed:
exiv2, gifsicle, hugin, imagemagick

The usage of this script is quite simple and can be viewed by calling the script without parameter or using the -h option.

user@computer:/my/path$ -h
All dependencies found.
Usage: to_gif [-c colourSpaceSize] [-h] [-v] [-r] [-s relativeSize] [-d delayInhundredthSeconds] picturesAsWildcardOrList
 -c Determines the size of the colourspace, can be ommited in most cases. If needed try 256.
 -h Showing the helpstring, this is also done by default if you use the command without arguments.
 -v Make the command verbose.
 -r Don't remove temporary files, this will result in multiple intermediate files as well as the final gif.
 -s The wanted size of the new image, relative to the old size in percent.
 -d The time delay between the images in hundredths of a second.

A typical call would look like this: *.jpg

A more sophisticated call using a one second delay and shrinking the gif to 50% of the original size looks like this: -c 256 -d 100 -s 50 *.jpg

Using my script, which can be downloaded from github here, makes it extremely easy to create aligned animated gifs.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: