How Animated GIFs Store Canvas Dimensions

Animated GIFs efficiently store large canvas dimensions while using smaller individual frame updates by separating global screen specifications from localized frame data. The format defines a master canvas size in a global header, while each subsequent frame contains its own dimensions and coordinate offsets. This design allows the file to update only the modified portions of the screen rather than rendering the entire canvas on every frame, significantly reducing overall file size.

The Logical Screen Descriptor

At the beginning of any GIF file (after the signature and version block), the file format defines the Logical Screen Descriptor. This block establishes the overall canvas for the animation and contains:

Every frame in the animation renders onto this designated logical screen. The dimensions set here remain constant throughout the entire playback of the GIF.

Image Descriptors and Local Coordinates

Instead of redrawing the entire logical screen for every tick of the animation, individual frames are encoded using an Image Descriptor block. Each frame acts as an independent sub-image placed on the larger canvas.

The Image Descriptor specifies four critical spatial parameters:

  1. Image Left Position: The X-coordinate (horizontal offset) where the top-left corner of the frame should appear on the logical screen.
  2. Image Top Position: The Y-coordinate (vertical offset) where the top-left corner of the frame should appear on the logical screen.
  3. Image Width: The actual width of the update region.
  4. Image Height: The actual height of the update region.

Because the frame's width and height are decoupled from the logical screen's width and height, an individual frame update can be as small as a few pixels wide and tall, positioned anywhere within the boundary of the logical screen.

The Role of the Graphics Control Extension

To make partial updates visually coherent, the GIF89a specification utilizes the Graphics Control Extension (GCE), which precedes each frame's Image Descriptor. The GCE defines:

Delta Encoding for Optimization

By pairing a static Logical Screen Descriptor with localized Image Descriptors and transparency, animated GIFs achieve a form of spatial delta compression. If only a small element moves—such as a character blinking or a cursor moving—the GIF only encodes the bounding box containing the altered pixels and places it onto the larger canvas using its coordinate offsets. Decoders composite these smaller rectangles directly onto the larger logical screen in real time.