Every extension starts with the byte 21, then a label that says which one
it is, then its data. Fixed fields go first, as a sub-block with a length byte, and any
further data follows as sub-blocks: length bytes of 1 to 255, ended by a zero-length one,
the block terminator.
| Label | Extension | Length |
|---|---|---|
F9 | Graphic control | 8 bytes |
FE | Comment | varies |
01 | Plain text | varies |
FF | Application | varies |
Graphic control extension
This extension gives the next image its delay, its transparent colour and what becomes of it afterwards. It applies to the first image or plain text block after it, and at most one may come before each of those.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 1 | u8 | introducer | 21. |
| 1 | 1 | u8 | label | F9. |
| 2 | 1 | u8 | block size | 4, the fixed bytes that follow. |
| 3 | 1 | u8 | flags | See below. |
| 4 | 2 | u16 | delay | The delay in hundredths of a second before the next frame. 0 means no delay. |
| 6 | 1 | u8 | transparent index | The colour index that stands for transparent, if the flag is set. |
| 7 | 1 | u8 | terminator | 00. |
| Bits | Name | Meaning |
|---|---|---|
| 7–5 | reserved | Should be 0. |
| 4–2 | disposal method | What happens to this frame next: 0 not specified, 1 leave it, 2 restore to background, 3 restore to previous. 4 to 7 are not defined. See Animation. |
| 1 | user input | 1 means processing waits for input from the user, or until the delay ends, whichever comes first. The specification asks encoders not to set it without a delay. |
| 0 | transparent colour | 1 if the transparent index is used: pixels of that index leave the canvas unchanged. |
00000019 21 F9 04 00 00 00 00 00
Comment extension
| Offset | Size | Name | Description |
|---|---|---|---|
| 0 | 1 | introducer | 21. |
| 1 | 1 | label | FE. |
| 2 | … | comment | Data sub-blocks holding the text, then the terminator. |
The text is not part of the picture and readers do not draw it. The specification recommends plain ASCII.
Plain text extension
Text to draw on the canvas in a fixed grid of character cells. It is a graphic block, so a graphic control extension can precede it. Almost no reader draws it, including browsers; the explorer lists the text but does not draw it.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 1 | u8 | introducer | 21. |
| 1 | 1 | u8 | label | 01. |
| 2 | 1 | u8 | block size | 12. |
| 3 | 2 | u16 | text grid left | The canvas column of the grid. |
| 5 | 2 | u16 | text grid top | The canvas row of the grid. |
| 7 | 2 | u16 | text grid width | The grid’s width in pixels. |
| 9 | 2 | u16 | text grid height | The grid’s height in pixels. |
| 11 | 1 | u8 | cell width | The width of a character in pixels. |
| 12 | 1 | u8 | cell height | The height of a character in pixels. |
| 13 | 1 | u8 | foreground | The global colour table index of the text. |
| 14 | 1 | u8 | background | The global colour table index behind the text. |
| 15 | … | text | Data sub-blocks of the characters, then the terminator. |
Application extension
Data for a particular application, identified by name, so that other readers can skip it.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 1 | u8 | introducer | 21. |
| 1 | 1 | u8 | label | FF. |
| 2 | 1 | u8 | block size | 11. |
| 3 | 8 | ASCII | identifier | Eight characters naming the application. |
| 11 | 3 | authentication | Three bytes the application can use to check the extension. | |
| 14 | … | data | Data sub-blocks that only the application defines, then the terminator. |
Looping: NETSCAPE2.0
GIF89a has no field that says an animation should repeat. Netscape Navigator 2.0
added it in 1995 with an application extension, and it is now what almost all readers
look for. The identifier and code spell NETSCAPE2.0 and it holds one
sub-block of 3 bytes: the byte 1, then a 16-bit loop count.
21 FF 0B 4E 45 54 53 43 41 50 45 32 2E 30 03 01 00 00 00
A loop count of 0 means loop forever. A count of n is commonly taken to mean
the animation plays n further times after the first. Other programs write the same
block as ANIMEXTS1.0, which the explorer reads the same way.
XMP metadata
Adobe stores XMP as an application extension with the identifier XMP Data
and code XMP, but not in sub-blocks: the UTF-8 packet comes straight after
the identifier, with no length bytes in it. To let a reader that does not know this
walk past it as if it were sub-blocks, a 258-byte magic trailer follows the packet:
01, then FF down to 00, then 00. A
reader taking the packet’s bytes for length bytes lands somewhere in the trailer, and
the ramp carries it to a real terminator.
ICC colour profiles
An ICC profile is stored as an application extension with the identifier
ICCRGBG1012 (ICCRGBG1 and code 012), and the
profile in ordinary data sub-blocks.
Other extensions
A reader that does not know a label must still skip the extension, by reading its sub-blocks to the terminator. The same applies to any application extension it does not recognise.