A GIF with several images is an animation only by convention: the file is a series of images, and the graphic control extension before each one says how long it stays and what to do with it afterwards. An image can be smaller than the canvas, so a frame usually holds only what changed.
Drawing the frames
A reader keeps a canvas the size of the logical screen, then for each image:
- Disposes of the previous frame as its disposal method says.
- Draws this image at its position on the canvas, using its local colour table or else the global one. Pixels of the transparent index, and pixels of a colour number past the end of the table, leave the canvas unchanged.
- Shows the canvas for the delay given, then moves to the next image.
The canvas starts out blank. Browsers treat that blank canvas as fully transparent rather than as the background colour.
Disposal methods
Bits 4 to 2 of the extension’s flags say what happens to a frame once its delay has passed, before the next is drawn:
| Value | Name | What happens |
|---|---|---|
| 0 | Not specified | The reader need not do anything; in practice the frame stays. |
| 1 | Do not dispose | The frame stays on the canvas. |
| 2 | Restore to background | The frame’s area becomes the background colour. Browsers clear it to transparent instead. |
| 3 | Restore to previous | The frame’s area goes back to what was there before the frame was drawn. |
| 4–7 | Not defined | Browsers treat 4 like 3, as some older files use it that way. |
The explorer composes frames the way browsers do, so that what it shows matches what the same file does when played. Pictures shown by Show frame are the canvas after that frame is drawn.
Delay
The delay is a 16-bit number of hundredths of a second, counted once the frame has been drawn. A delay of 0 means no delay, which is often used to draw a picture from several images without pause. Many browsers lengthen very short delays, such as 0 or 1 hundredth, to about a tenth of a second.
Looping
GIF89a itself does not say that an animation repeats. The NETSCAPE2.0 application extension gives a loop count, and readers that do not find one play the animation once.
Transparency
A pixel holding the transparent colour index does not change the canvas. That lets a frame hold only the pixels that differ from the last, while the rest of the frame shows through, and is why GIF is often used for simple moving pictures over a plain background. The transparent colour is set frame by frame by the graphic control extension.