Simple batch GIF Animation for Weather Forecast

Overview

In this post we’ll discuss a simple method for producing an animated GIF from a collection of separate images, using the ImageMagic command line interface and then setting it as a batch job to run every day.

Background

A common need in representing static information on the web is to somehow show changes in state. In this case, it was a simple need to take a dozen or so static images showing dry and saturated adiabatic lapse rates.

An example of which is shown below and is a snap shot for one hour at one physical location for atmospheric conditions. This changes from hour to hour so we want to animate this so the view can see how the conditions chnage during the day.

Pre-Requistites

The rest of this article makes a few assumptions on the likely setup in use. These are:

That the source image/s are avaialble via a simple HTTP pull (i.e. not embedded in any other pages).

That ImageMagick is available on the command line.

That the UNIX shell script will be hosted somewhere (sorry Microsoft users).

It is possible to schedule the script using a cron interface or similar.

In which we set where we send the output to, where the script is, the location of the source images and an output filename prefix. Then we delete any existing temporary files (which we leave in case we need to look at them if the image fails).

Step 2 – Grab The Images

This can be tricky depending on your hosting supplier. If you have complete control, you can use wget but it has been found the curl will often be available if wget is not.

Here we use curl and simply get the images one line at a time. To keep things simple, there is no error checking here. Hence, if the file is empty or the curl fails, then the image will probably have blank pages in it.

The references below will give a breakdown of the options used, but put simply, we have one long command-line entry (split using back-slashes), which is 800×800 pixels, a one second delay between each image that loops forever. We also send the output to the target location.

Easy.

Step 4 – Automation

If you have access to a cron or similar mechanism, making this a daily event is as easy as adding the following to the crontab file. Assuming the script file is called pullskewt.sh in the cgi-bin/skewt folder of your hosted area, add this to run the job at 06:00 every day:

* 6 * * * cgi-bin/skewt/pullskewt.sh

The name “skewt” comes from the graph name used on the source. It can be anything you like.

Useful References

In terms of background information, the following are useful in explaining the detail of GIF animation and the use of ImageMagick: