gif
Pure-Rust GIF encoder and decoder with high-level Encoder/Decoder types and streaming support.
Repository Health
Technical Analysis
gif is a pure-Rust library for encoding and decoding GIF images, maintained as part of the image-rs organization. It provides everything needed to read and write GIF files, including animated GIFs, through a clean high-level API built around Encoder and Decoder types.
The decoder streams frames one at a time and can expand output to RGBA, while the encoder writes frames with optional color quantization. As a foundational building block of the broader image crate, gif is battle-tested, dependency-light (built on the weezl LZW codec), and used across the Rust ecosystem.
What You Get
- A high-level Decoder that streams GIF frames with configurable RGBA/indexed output
- A high-level Encoder for writing single-frame and animated GIFs
- LZW compression and decompression via the weezl codec
- Optional color quantization for reducing images to a GIF palette
- Support for interlacing, transparency, and per-frame disposal metadata
Common Use Cases
- Decoding animated GIFs frame by frame for playback or processing
- Encoding image sequences into animated GIF files
- Serving as the GIF backend for the image crate and image pipelines
- Converting between GIF and raw RGBA pixel buffers
Under The Hood
Architecture - gif is a single library crate whose src splits cleanly into an encoder.rs writing side, a reader/ module for streaming decoding, a shared common.rs (frame, block, and disposal types), and traits.rs for pixel/output abstractions. Decoding is pull-based: DecodeOptions::read_info returns a decoder that yields frames via read_next_frame, while encoding writes a global header then per-frame blocks.
Tech Stack - Written in Rust (edition 2024, MSRV 1.88) with a minimal dependency footprint: weezl for LZW en/decoding and an optional color_quant for palette quantization. Dev tooling uses criterion for benchmarks and glob for test fixtures.
Code Quality - The repo is well-tested with a large tests/ suite (roundtrip, decode, crash/regression corpora, truncated and interlaced inputs), fuzz targets under fuzz/, AFL harnesses, and a C API crate, reflecting the hardening expected of a widely-deployed image parser. CI runs on GitHub Actions.
API Design - The public API is small and ergonomic — DecodeOptions/Decoder and Encoder/Frame — with builder-style configuration for color output. Documentation on docs.rs includes runnable decode and encode examples, giving a gentle learning curve for anyone processing GIFs.