Skip to main content

TinyPNG

A lightweight, minimal PNG library.

Installation

pip install lib-tiny-png

Usage

from tiny_png import ColorType, load_image, save_image

width, height = 4, 2
pixels = bytes([255, 0, 0, 255] * (width * height))  # Red RGBA pixels
save_image("red.png", width, height, pixels)

image = load_image("red.png")
if image.error:
    print(image.error)
else:
    print(image.width, image.height, image.color_type)  # 4 2 ColorType.RGBA
    print(image.buffer == pixels)  # True

gray = bytes(range(16))
save_image("gray.png", 4, 4, gray, ColorType.GRAYSCALE)

API Reference

ColorType

GRAYSCALE (1 byte per pixel), GRAYSCALE_ALPHA (2), RGB (3), RGBA (4).

save_image(file_path, width, height, data, color_type=ColorType.RGBA)

Saves row-major 8-bit pixels as a PNG file.

Parameters:

  • file_path (str) - The output file path.
  • width, height (int) - The image size in pixels.
  • data (bytes, bytearray or any uint8 buffer) - Pixels of size width * height * channels.
  • color_type (ColorType, optional) - The color type of the pixels.

Returns:

  • bool - True if the image is saved.

Raises:

  • ValueError - If the size of data does not match the image size.

load_image(file_path)

Loads a PNG file.

Returns:

  • PNGData - With fields width, height, color_type, buffer (bytes) and error (str, empty on success).

Metadata

Release files for lib-tiny-png 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lib-tiny-png 0.1.0
File Size Uploaded Provenance
lib_tiny_png-0.1.0.tar.gz 12.7 kB Without provenance Details

Release files / lib_tiny_png-0.1.0.tar.gz

Download URL lib_tiny_png-0.1.0.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
87824a601885888fdb0772449459116ed8b70a8e532147744e801ab52727af71
BLAKE2b-256 checksum
How to use checksums
6a5e3029cb48af2d85d03934a826d92c077d936abeca3b9c63f35b5e8e510ae2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.13

Security for lib-tiny-png 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page