tinypng is a tiny, header-only PNG writer in a single tinypng.h file, written in C23.
It has no dependencies: no libpng and no zlib. Image data is emitted as DEFLATE "stored" (uncompressed) blocks wrapped in a zlib stream, so the output is a valid, standard PNG that any image viewer can open. The required CRC-32 and Adler-32 checks are computed inline.
The resulting files are larger than compressed PNGs, but the code is small and easy to drop into any project.
Include the header anywhere for the declaration. In exactly one translation unit, define TINYPNG_IMPLEMENTATION before the include:
#define TINYPNG_IMPLEMENTATION
#include "tinypng.h"
bool write_png(FILE *fp, const uint32_t *pixels, uint32_t width, uint32_t height);Pixels are 32-bit RGBA in memory order (byte 0 = R, byte 1 = G, byte 2 = B, byte 3 = A). write_png returns true on success.
main.c writes a 64x64 RGBA gradient to output.png:
gcc -std=c23 -Wall -Wextra -O2 -o tinypng main.c
./tinypng- A C compiler that supports C23.
- License: The Unlicense (public domain). See the
LICENSEfile. - Version: 1.0.0