PyPNG

0.20220715.0 · active · verified Thu Apr 09

PyPNG is a pure Python library designed for reading, writing, and manipulating PNG (Portable Network Graphics) images. It provides a simple, Pythonic interface and boasts no external dependencies. The current stable version is `0.20220715.0`, with updates released as needed.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple grayscale PNG image from a Python list of lists representing pixel data. It uses the `png.from_array` function for convenience and saves the image to a file.

import png
import os

# Create a simple 2x2 grayscale image (Luminance) with a bit depth of 8
rows = [
    [255, 0], # White, Black
    [0, 255]  # Black, White
]

# Create an image from a 2D array and save it
image_file_path = 'simple_image.png'
png.from_array(rows, 'L').save(image_file_path)

print(f"Image saved to {image_file_path}")

# Clean up the created file
# os.remove(image_file_path)

view raw JSON →