Department of Mathematics FAS Harvard University One Oxford Street Cambridge MA 02138 USA Tel: (617) 495-2171 Fax: (617) 495-5132
FAS Computer Services to Harvard University IT: (617) 495-7777.
The graphics interchange format GIF is besides JPG and PNG one of the most popular graphics formats for the web. Its strength are animation (not possible with JPG and PNG, there is an emerging MNG although), transparency option (not possible with JPG and not consistently supported by browsers with PNG) and excellent compression for pictures with only a few colors and large areas of the same color.

Viewing GIF's

The xv viewer is an older but still one of the best image viewers in X. With "xv file.gif" you can see the graphics and do many graphics manipulations. In Unix, you can see with "xanim file.gif", "animate file.gif" an animated gif. You also just can call "netscape file.gif" to see an animated or nonanimated GIF "file.gif".


Producing GIF's

GIF files can be exported from practially all graphics programs like the Gimp, Photoshop, Illustrator, Fireworks etc. From Mathematica, you get a gif "file.gif" for example with a command Display["file.gif",Plot[Sin[x],{x,0,3}],"GIF"]. Other programs like the ray tracing program Povray or in C you can export PPM files, which are then converted into GIF with "ppmtogif file.ppm>file.gif" or "convert file.ppm file.gif". Note that the "convert" routine produces by default badly compressed GIF's.


Animated GIF's

Given several gif files like "file1.gif", "file2.gif", ... ,"file10.gif", the Unix program "gifmerge" allows to combine them to an animated gif for example with "gifmerge -l0 -20 file*.gif>movie.gif", where the frames follow each other in a time interval of 20 milliseconds. See the documentation and source. A program running under Unix with even more options is GIFsicle . Animated gifs can also exported directly from the the Gimp, where each layer will just be a frame of the animated GIF. The image magic "convert" routine produces from a PS document "file.ps" an animated gif "file.gif" with "convert file.ps file.gif". The script flattengif (which uses gifsicle and the now standard netppm routines) produces from an animated gif a single-framed gif, where the frames are stacked onto each other. This can be used in scripts like latex2all, which turns a LaTeX file to PS,DVI,PDF,GIF files.

Small GIF's

Use as few colors as possible. Don't dither the picture, when making the RGB -> Indexed transition. Clean out the picture by hand if necessary. Use conversion programs which produce small pictures. The gimp, the conversion program ppmtogif, or the viewer xv produce well compressed files, the Imagemagic routines (convert) do not. compressgif is a small shellscript which assures that a small GIF is obtained.

GIF Specification

The technical GIF87a specification The latest technical GIF89 specification.

The LZW patent

Because GIF uses an adaptation of the Lempel Ziv Welch (LZW) algorithm for image compression which Unisys unfortunatly was able to patent, developers of GIF-based software are required to obtain a license under this patent. Read more information on that or on the history of the controversy. The basic U.S. patent on LZW compression expired in June, 2003. (See more details ).


Simplicity, Clarity, Generality B.W. Kernighan, R. Pike, in "The Practice of Programming".
Privacy
HTML CSS