Introduction
GIF89a is the version of GIF that CompuServe published in 1989 and revised in 1990. It keeps everything in GIF87a and adds extension blocks. The graphic control extension gives each frame a delay, a disposal method and a transparent colour, which is what makes animated and transparent GIFs possible. Comment, plain text and application extensions carry the rest.
Nearly every animated GIF on the web is a GIF89a file.
Structure
A GIF starts with a 6-byte header, GIF89a, and a 7-byte logical screen
descriptor giving the canvas size (little-endian) and whether a global colour table
follows. The rest of the file is a series of blocks, each introduced by one byte:
21 for an extension, 2C for an image and 3B for
the trailer that ends the file.
An image block has a 10-byte descriptor, an optional local colour table, the LZW
minimum code size and the compressed data. Image data and extension data are written as
sub-blocks: a length byte of up to 255 followed by that many bytes, ending with a
zero-length sub-block. A graphic control extension before an image sets its delay and
transparent colour, and the NETSCAPE2.0 application extension sets the loop
count.
0HeaderGIF89a6 bytes6Logical screen descriptor width, height, flags, background colour7 bytes13Global colour table 3 bytes per colour, optional6 to 768 bytes…Frames repeated for each imagevaries21 F9Graphic control extension delay, transparency, disposal8 bytes2CImage descriptor position, size, flags10 bytes…Local colour table optional, then the LZW data sub-blocksvaries
…Trailer3B1 byte
Telling it apart
The file starts with GIF89a (47 49 46 38 39 61). A
GIF87a file differs only in those last three
characters, and has no extension blocks.
Variants
- Graphics Interchange Format (GIF87a) – the first GIF: palette images on a logical screen, with no extensions
- Graphics Interchange Format (GIF89a) – the current GIF, with extensions for transparency, timing and animation
Links
Software
- GIMP – free image editor that opens, edits and saves GIFs, including animations as layers (Windows, macOS, Linux)
- Adobe Photoshop – image editor that opens GIFs and exports them, with frames from its timeline (Windows, macOS)
- Photopea – image editor in the browser that opens and saves GIF (web browser)
- Ezgif – online tool for making, cutting and optimising animated GIFs (web browser)
- Gifsicle – command-line tool that edits and optimises GIF animations (Windows, macOS, Linux)
- ImageMagick – command-line tools that convert to and from GIF (Windows, macOS, Linux)
- IrfanView – image viewer that plays and converts GIFs (Windows)
- XnView MP – image viewer and batch converter (Windows, macOS, Linux)
Developers
Reference
- GIF89a specification – CompuServe’s revised specification, 1990