.GIF
Graphics Interchange Format
Introduction
GIF was introduced by CompuServe in 1987 (version 87a) and extended in 1989 (version 89a). Each frame holds up to 256 colours from a palette, compressed without loss using LZW. Version 89a added transparency, frame delays and comments, which together made GIF the format for short looping animations on the web.
The LZW patent held by Unisys led to the creation of PNG in the 1990s. The patent expired in 2003 and 2004, and GIF remains widely supported.
Software
- GIMP (Windows, macOS, Linux)
- Adobe Photoshop (Windows, macOS)
- Photopea (web browser)
- Ezgif (web browser)
- Gifsicle (Windows, macOS, Linux)
- ImageMagick (Windows, macOS, Linux)
- IrfanView (Windows)
- XnView MP (Windows, macOS, Linux)
Structure
A GIF starts with a 6-byte header, GIF87a or 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