Skip to content
Simple, modern libpng alternative
C Meson C++ CMake
Branch: master
Clone or download
randy408 tests: add fuzz target entry point
this does not require libFuzzer
Latest commit dd4936f Aug 16, 2019

Gitter Windows CI Fuzzing Status Coverity codecov tag


libspng is a C library for reading and writing Portable Network Graphics (PNG) format files with a focus on security and ease of use.

libspng is an alternative to libpng, the projects are separate and the APIs are not compatible.


The goal is to provide a fast PNG library with a simpler API than libpng.



Feature libspng libpng stb_image lodepng
Decode to RGBA8/16
Decode from stream
Gamma correction
Fuzzed by OSS-Fuzz
Progressive read *
Doesn't require zlib
Encoding *
Animated PNG * ✓**

* Feature in planning phase

** With a 3rd party patch

Getting spng

Download the latest release and include spng.c/spng.h in your project, you can also build with CMake or Meson. Refer to the documentation for details.


/* Create a context */
spng_ctx *ctx = spng_ctx_new(0);

/* Set an input buffer */
spng_set_png_buffer(ctx, buf, buf_size);

/* Determine output image size */
spng_decoded_image_size(ctx, SPNG_FMT_RGBA8, &out_size);

/* Decode to 8-bit RGBA */
spng_decode_image(ctx, out, out_size, SPNG_FMT_RGBA8, 0);

/* Free context memory */

See example.c.


Code is licensed under the BSD 2-clause "Simplified" License.

The project contains optimizations and test images from libpng, these are licensed under the PNG Reference Library License version 2.

Security & Testing

Code is written according to the rules of the CERT C Coding Standard. All integer arithmetic is checked for overflow and all error conditions are handled gracefully.

The library is continuously fuzzed by OSS-Fuzz, releases are scanned with Clang Static Analyzer, PVS-Studio, and Coverity Scan.

The test suite consists of over 700 test cases, 175 test images are decoded with all possible output format and flag combinations and compared against libpng for correctness.


Releases follow the semantic versioning scheme with a few exceptions:

  • Releases from 0.4.0 to 0.8.x are stable
  • 0.8.x will be maintained as a separate release branch from 1.0.0

Note that 1.0.0 will introduce little to no breaking changes.


Online documentation is available at

Known Issues

  • Text and iCCP chunks are not read.
  • spng_crc_set_action() is partially implemented, SPNG_CRC_DISCARD has no effect.
You can’t perform that action at this time.