Return to UOCC HomeComputing News Home
Header bar

Save Space and Speed Up Your Web pages by Converting Gifs to Jpgs

By Joe St Sauver (joe@oregon.uoregon.edu)

Many web designers are used to relying primarily on gif-format images, when often jpg-format images are actually preferable.

For example, jpgs tend to be smaller than comparable gifs for continuous-tone photographic images, and they also render color more faithfully.

If you have thousands of existing images in gif format, the thought of converting them all to a different format might be a little daunting. Fortunately, however, you don't need to convert them one at a time. Instead, you can use this simple script on DARKWING to convert them en masse:

#!/bin/csh -x

foreach f ( *.gif )

set base = `basename $f .gif`

giftopnm $f | cjpeg -quality 50 > $base.jpg

end

(Note that the backticks on line three are just that: backtick marks, not apostrophes.)

The script assumes that your gifs have the suffix .gif and reside in your current directory. It also shows a typical JPEG quality factor of 50; higher or lower values may be appropriate if you want better image quality or better image compression. For seat-of-the-pants calibration, a sample image I converted had the following quality versus size relationship:

Original gif: 220520 bytes

QUALITY
SIZE
jpg @ quality 90 149242 bytes
jpg @ quality 80 97294 bytes
jpg @ quality 70 71116 bytes
jpg @ quality 60 56573 bytes
jpg @ quality 50 48203 bytes

A Few Caveats

Before you use this script, here are a few more things to keep in mind:

See man giftopnm and man cjpeg for more information on those two commands. If you run into problems or have questions, feel free to send mail to joe@oregon.uoregon.edu


Spring 1999 Computing News | Computing Center Home Page