PicScrub logoPicScrub
Back to Formats

GIF Format

Graphics Interchange Format

Block Structure

GIF is one of those formats that has outlived its expected lifespan by decades. Created by CompuServe in 1987, it's still everywhere today, mostly because of its animation support.

The format uses a block-based structure that's refreshingly straightforward compared to modern formats. A header, some descriptors, a color table, your image data, and a single-byte trailer to say "the end."

GIF File Structure

Header
LSD
GCT
Extensions
Image Data
Trailer
Header
6 bytes
GIF87a or GIF89a
LSD
7 bytes
Logical Screen Descriptor
GCT
768 bytes
Global Color Table (optional)
Extensions
100 bytes
Extension blocks (metadata)
Image Data
Variable length
Image descriptor + LZW data
Trailer
1 bytes
0x3B terminator

GIF Header

GIF Signature
Version (89a)
Width (640)
Height (480)
Packed Fields
Background Index
Pixel Aspect Ratio
OffsetHexASCII
0000
4749463839618002E001F70000
GIF89a.......

Version Differences

GIF87a

Original spec. No extension blocks.

GIF89a

Added extensions, animation, transparency.

Extension Blocks

GIF89a (the 1989 revision) added extension blocks, which is how GIF got animation support. All extension blocks start with 0x21 followed by a type byte, which makes them easy to spot when you're scanning through a file. Some of these we want to keep (animation timing), others we want to remove (comments).

Graphic Control Extension (0xF9)

Controls animation timing, transparency, and disposal method. Precedes each image descriptor in animated GIFs. Always preserved.

21 F9 04 [disposal] [delay] [transparent] 00

Comment Extension (0xFE)

Plain text comments. Can contain any information including author, creation date, software, or personal notes. Removed by PicScrub.

21 FE [size] [comment data...] 00

Application Extension (0xFF)

Application-specific data. Most important: NETSCAPE2.0 for animation looping. Can also contain XMP metadata.

21 FF 0B [app identifier] [auth code] [data...] 00

Plain Text Extension (0x01)

Rarely used. Renders text using the GIF color table. Mostly ignored by modern software.

Application Extensions

NETSCAPE2.0:Animation Loop

Controls how many times an animated GIF loops. Value of 0 means infinite loop.

Extension intro
Block size (11)
NETSCAPE2.0
Sub-block size
Sub-block ID
Loop count
Terminator
OffsetHexASCII
0000
21FF0B4E45545343415045322E300301000000
!..NETSCAPE2.0.....

PicScrub preserves NETSCAPE2.0 to maintain animation behavior.

XMP Data:Extensible Metadata Platform

Application identifier: XMP DataXMP. Contains full XMP/RDF metadata in XML format.

PicScrub removes XMP application extensions.

Animation Preservation

The tricky part with GIF is distinguishing between animation data (which we need to keep) and metadata (which we want to remove). Both live in extension blocks, so we can't just strip all extensions.

Preserved for Animation

  • • NETSCAPE2.0 loop count
  • • Graphic Control Extensions
  • • Frame delays
  • • Disposal methods
  • • Transparency indices
  • • Local color tables

Removed

  • • Comment extensions
  • • XMP application blocks
  • • Unknown application blocks
  • • Plain text extensions

How PicScrub Processes GIF

1

Validate Header

Check for GIF87a or GIF89a signature

2

Copy Header Data

Preserve LSD and Global Color Table unchanged

3

Filter Extensions

Keep NETSCAPE2.0 and Graphic Control, remove Comment and XMP

4

Preserve Image Data

Copy all image descriptors, LCTs, and LZW data unchanged

5

Write Trailer

End file with 0x3B trailer byte

LZW Compression

A quick note on GIF's image data: it uses LZW compression, which was actually patented until 2004 (causing all sorts of drama in the '90s). PicScrub doesn't touch the compressed data at all. We copy it byte-for-byte, which means zero quality loss.

Why This Matters

By preserving the original LZW data, PicScrub ensures:

  • • No quality loss (bit-perfect image preservation)
  • • Fast processing (no decode/encode cycle)
  • • Identical file size for image data

GIF Metadata Limitations

The good news about GIF is that it predates the EXIF standard, so there's no GPS coordinates or camera info to worry about. The metadata concerns are more mundane.

What Can Leak

GIF's privacy concerns are relatively minor compared to JPEG:

  • • Comment extensions (sometimes containing author notes)
  • • XMP metadata (rare, but possible)
  • • Software identification in application blocks