png

Robust, high-performance PNG and APNG decoder and encoder in pure Rust

Library
Cargo
v0.18.1
512stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
64/100Good
Development Activity64
Maintenance24
Community88
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture87
Code Quality90
Innovation82
Learning Curve62

png is a pure-Rust library for decoding and encoding PNG images, including animated PNG (APNG). It contains no unsafe code, is continuously fuzzed on OSS-Fuzz, and delivers performance typically on par with or better than libpng.

The crate powers the wider image-rs ecosystem and ships a fast encoding mode built on fdeflate that beats libpng’s fastest mode while producing better compression ratios. It exposes a streaming Decoder and Encoder API for reading and writing PNG data with full control over color types, bit depth, filtering, and metadata.

What You Get

  • A streaming PNG Decoder that reads images incrementally
  • A configurable Encoder with color type, bit depth, and filter control
  • Animated PNG (APNG) decoding and encoding support
  • A fast fdeflate-powered encoding mode faster than libpng
  • Text and metadata chunk handling plus sRGB support

Common Use Cases

  • Loading PNG images into applications and image pipelines
  • Encoding rendered or processed pixel data to PNG files
  • Reading and writing animated APNG sequences
  • Extracting or embedding PNG text metadata and color profiles

Under The Hood

Architecture - The crate splits cleanly into a decoder module (src/decoder) that parses PNG chunks incrementally and an encoder.rs that writes them, with a filter module implementing the PNG scanline filters and adam7.rs handling interlacing. Shared code lives in chunk.rs, common.rs, and traits.rs, while text_metadata.rs and srgb.rs handle ancillary chunks. Compression is delegated to the deflate crates rather than reimplemented.

Tech Stack - Pure Rust (2021 edition, rust-version 1.73) with no unsafe code. It depends on fdeflate for fast deflate encoding, flate2 and miniz_oxide (with SIMD) for compression, crc32fast for chunk checksums, and bitflags for option handling. An optional unstable feature enables extra decode speedups on nightly.

Code Quality - The project is battle-tested and continuously fuzzed on OSS-Fuzz, with a fuzz/ harness, a png-afl target, a tests/ suite, and benches/ for performance tracking. CI runs via GitHub Actions. The absence of unsafe code plus fuzzing gives strong confidence in its robustness against malformed input.

API Design - The Decoder/Encoder API is straightforward: construct a Decoder over any Reader, obtain frame info, and read rows into a buffer; encoding mirrors this with a builder-style Encoder. docs.rs documentation and examples cover common flows, though full control over PNG’s many color types, bit depths, and filter strategies exposes the format’s inherent complexity.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search