PizzaPNG

PizzaPNG is a C++ library for easy generation of image files in the PNG format, in software for Windows. License: MIT.

Features

  • Simple API.
  • No dependencies. libpng is unneeded.
  • Automatically removes unneeded meta chunks added by GDI+.
  • Supports inserting custom binary chunks.
  • Header files don’t depend on Windows-specific header files.
  • Color subtype of PNG file (with trans­parency or not) is chosen auto­mati­cally based on whether there are (semi­)trans­parent pixels.

Example

The program below generates a 123×42 green image with 50% opacity and saves it as a file named example.png.

#include <cstdint>
#include <fstream>
#include <string>

#include "pizza-png/src/Image.h"

using std::ios;

int main() {
    uint16_t width  = 123,
             height = 42;

    MaratTanalin::PizzaPNG::Image image(width, height);

    for (uint16_t y = 0; y < height; y++) {
        for (uint16_t x = 0; x < width; x++) {
            image.addPixel(0, 255, 0, 127);
        }
    }

    std::string pngData = image;

    std::ofstream fs("example.png", ios::out | ios::binary | ios::trunc);
    fs.write(pngData.data(), pngData.size());
    fs.close();
}

Limitations

  • Only for Windows due to using GDI+.
  • Only 24-bit and 32-bit (24-bit with transparency) PNG files are supported.