Skip to main content

LastPNG for Pillow

LastPNG makes reading and saving PNG images in Pillow faster and optimizes file size by choosing the palette, bit depth, and color type automatically. Output remains standard PNG, preserving visible colors and transparency; RGB values in fully transparent pixels may change. Reading supports PNG and APNG, with Pillow handling metadata and animation composition.

Installation

Requires Python ≥3.10 and Pillow ≥11, ≤13.0.0.

pip install lastpng

Wheels bundle the native libraries; no separate libdeflate or Windows VC Redistributable installation is needed.

Usage

from PIL import Image
import LastPNGImagePlugin

# Select LastPNG explicitly when saving.
with Image.open("input.png") as image:
    image.save("output.png", format="LASTPNG", level=3)

# Use Rust decoding and LastPNG encoding by default throughout the process.
LastPNGImagePlugin.register_as_default()
with Image.open("input.png") as image:
    image.save("output.png", level=3)

Use register_as_default(encoder=False) to enable only Rust decoding and keep the current PNG encoder.

Choose a compression level from 1 (fastest) to 6 (experimental, highest effort). The default is 3.

Save options

Supports pnginfo, icc_profile, transparency, dpi, and exif. An ICC profile preserves the input color family.

In pnginfo, IHDR, PLTE, tRNS, IDAT, IEND, bKGD, hIST, sBIT, eXIf, and iCCP raise ValueError. LastPNG selects the output representation; use exif= for EXIF and icc_profile= for an uncompressed ICC profile.

For a unitless pixel aspect ratio or exact pixels-per-metre values, pass one pHYs chunk in pnginfo; it is written before IDAT. Combining it with dpi raises ValueError.

HDR mDCV (24 bytes) and cLLI (8 bytes) are accepted once each through pnginfo and written before PLTE and IDAT. mDCV requires cICP, in either input order.

Limitations and behavior

Formats and compatibility

Encoding supports single images in modes 1, L, I;16, P, RGB, LA, and RGBA. APNG saving uses Pillow's encoder. Decoding supports Adam7 interlacing and APNG.

Supports CPython with Pillow major versions 11, 12, and 13. Unsupported versions raise an error when importing the plugin.

Image access and animation

Keep the image unchanged until save() returns. Serialize loading, seeking, and pixel access on the same image object.

APNG decoding streams frames on demand, reading frame data once during forward playback, including gzip streams. Initialization may reread large headers; rewinding or retrying a failed native decode rereads the stream. Keep the file open while frames are needed.

Pillow's animation limitations apply, including unsupported I;16 blending with OP_OVER. Reopen the image after errors in Pillow metadata processing, frame transitions, or composition.

Damaged PNGs

With PIL.ImageFile.LOAD_TRUNCATED_IMAGES = True, decoding tolerates early EOF, missing rows, and damaged compressed data. Complete rows (including Adam7 pass rows) are retained; unrecovered pixels remain zero or retain the existing APNG canvas. CRC and Adler-32 checks are disabled, but Pillow still validates headers, metadata, and APNG frame controls and sequences.

Recovered pixels may differ from Pillow's zlib decoder. Rust's structural checks and static PNG memory limits can reject files Pillow accepts. For APNG, Rust's internal allocation budget is disabled; Pillow controls destination image allocation.

Without truncated loading, corrupt static PNG IDAT checksums or a missing chunk header after frame data cause errors that Pillow may tolerate during load(). APNG fdAT CRC errors are accepted, as in Pillow.

Building from source

A Rust toolchain and a C compiler are required. From the repository root:

python -m pip install ./python  # Install from the checkout.

# Build an sdist and wheel in python/dist/.
python -m pip install build
python -m build ./python

Metadata

Release files for lastpng 0.2.1

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

Source distribution (sdist)

Source distribution for lastpng 0.2.1
File Size Uploaded Provenance Actions
lastpng-0.2.1.tar.gz 150.6 kB With provenance Details for lastpng-0.2.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for lastpng 0.2.1
File Actions
lastpng-0.2.1-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for lastpng-0.2.1-py3-none-win_amd64.whl
lastpng-0.2.1-py3-none-musllinux_1_2_x86_64.whl Python 3 none Linux musl 1.2+ x86-64 Details for lastpng-0.2.1-py3-none-musllinux_1_2_x86_64.whl
lastpng-0.2.1-py3-none-musllinux_1_2_aarch64.whl Python 3 none Linux musl 1.2+ ARM64 Details for lastpng-0.2.1-py3-none-musllinux_1_2_aarch64.whl
lastpng-0.2.1-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details for lastpng-0.2.1-py3-none-manylinux_2_28_x86_64.whl
lastpng-0.2.1-py3-none-manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64 Details for lastpng-0.2.1-py3-none-manylinux_2_28_aarch64.whl
lastpng-0.2.1-py3-none-macosx_11_0_universal2.whl Python 3 none macOS 11.0+ universal2 (ARM64, x86-64) Details for lastpng-0.2.1-py3-none-macosx_11_0_universal2.whl

Total release size: 11.9 MB

Release files / lastpng-0.2.1.tar.gz

Download URL lastpng-0.2.1.tar.gz
Size 150.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ac2d2cf8a4d2c99dce7580a2aec74101d71ced0697e6da2e13c96d5833d466a4
BLAKE2b-256 checksum
How to use checksums
c2bd8a7b2032ec62d4d7eceffac3fd917ae2ad6daaefbc620eb5fc18f617418f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

SLSA Build Provenance Attestation

PyPI verified that this artifact, at this checksum, originated from the builder listed below.

Built by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / lastpng-0.2.1-py3-none-win_amd64.whl

Download URL lastpng-0.2.1-py3-none-win_amd64.whl
Size 596.3 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
a37b681202588306053d9952011209d75221ea678f5d61ad8432c15515d85f6d
BLAKE2b-256 checksum
How to use checksums
2d37b864266949dffb6837b7882a4080297dc1c3288a0ba3fc435e0fe110b32c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

SLSA Build Provenance Attestation

PyPI verified that this artifact, at this checksum, originated from the builder listed below.

Built by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / lastpng-0.2.1-py3-none-musllinux_1_2_x86_64.whl

Download URL lastpng-0.2.1-py3-none-musllinux_1_2_x86_64.whl
Size 2.4 MB
Tags Linux musl 1.2+ x86-64 Python 3
SHA-256 checksum
How to use checksums
b3d1fd682e3b452bc0cbc24f5f76d7bd3bd404ac999ee14869209aa6156de2e8
BLAKE2b-256 checksum
How to use checksums
cbb495cd0ec4d5f204f01bc7a9fd2eae70a94a4b12b4c13c5dc44500085b5bb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

SLSA Build Provenance Attestation

PyPI verified that this artifact, at this checksum, originated from the builder listed below.

Built by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / lastpng-0.2.1-py3-none-musllinux_1_2_aarch64.whl

Download URL lastpng-0.2.1-py3-none-musllinux_1_2_aarch64.whl
Size 2.4 MB
Tags Linux musl 1.2+ ARM64 Python 3
SHA-256 checksum
How to use checksums
457c9af6265dab4fb868f7e50f214b49a384440e0f7e07b0e435ba66d2fd5e59
BLAKE2b-256 checksum
How to use checksums
2ffd7070ddd907f6368dc7a46292fe9c5e105f48bba28e7c873c94b3705b96bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

SLSA Build Provenance Attestation

PyPI verified that this artifact, at this checksum, originated from the builder listed below.

Built by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / lastpng-0.2.1-py3-none-manylinux_2_28_x86_64.whl

Download URL lastpng-0.2.1-py3-none-manylinux_2_28_x86_64.whl
Size 2.7 MB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
e759b412194004510cd72cdaefef5acb8c3e0c28bd9092f7d25cbfb0f253fce7
BLAKE2b-256 checksum
How to use checksums
1ead3c1289988eac5a5c46e4520db4b9aa84a7664786c55d9136a97a528a76d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

SLSA Build Provenance Attestation

PyPI verified that this artifact, at this checksum, originated from the builder listed below.

Built by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / lastpng-0.2.1-py3-none-manylinux_2_28_aarch64.whl

Download URL lastpng-0.2.1-py3-none-manylinux_2_28_aarch64.whl
Size 2.3 MB
Tags Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
3f5012a85078a9d8cfa4ddc24bbca4bcd6197114031a72696d3e5848f3cbbc94
BLAKE2b-256 checksum
How to use checksums
be8e39eab0b8d3cf1d45067c58aa67a4cea99e4b8d5231409467a7aa6538ce60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

SLSA Build Provenance Attestation

PyPI verified that this artifact, at this checksum, originated from the builder listed below.

Built by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / lastpng-0.2.1-py3-none-macosx_11_0_universal2.whl

Download URL lastpng-0.2.1-py3-none-macosx_11_0_universal2.whl
Size 1.4 MB
Tags Python 3 macOS 11.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
98d937ce2dd57c60605519810401d7a41b0999099a2216a1ffb3d6c3a4a0dfcb
BLAKE2b-256 checksum
How to use checksums
f3cc2c816ad74ac164866a40f709ef61f225d4d9193d4a9e4dbdc38541f8192a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

SLSA Build Provenance Attestation

PyPI verified that this artifact, at this checksum, originated from the builder listed below.

Built by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Security for lastpng 0.2.1

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.

Full provenance

All 7 files in this release have been uploaded with provenance metadata.

Select from 7 files

Attestations for lastpng-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

SLSA Build Provenance Attestation

PyPI verified that this artifact, at this checksum, originated from the builder listed below.

Built by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

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.2.1 This release

7 release files Full 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