Skip to main content

Fast libspng-based PNG decoder. Fork of pyspng.

Project description

PyPI version

Note: This is a fork of pyspng which can be found here: https://github.com/nurpax/pyspng/. See below for a list of differences.

Pyspng is a small library to for efficiently loading PNG files to numpy arrays. Pyspng does not offer any image manipulation functionality.

Pyspng was originally written to speed up loading uncompressed (PNG compression level 0), making the PNG file format more suitable to be used in machine learning datasets. Pyspng uses the native libspng library for fast PNG decoding. Synthetic benchmarks indicate pyspng to be roughly 2-3x faster in loading uncompressed PNGs than the Python Pillow library.

Scripting Example

import numpy as np
import pyspng
from pyspng import ProgressiveMode

# DECODING
with open('test.png', 'rb') as fin:
    nparr = pyspng.load(fin.read())

# ENCODING
binary = pyspng.encode(
    nparr,
    # Options: NONE (0), PROGRESSIVE (1), INTERLACED (2)
    progressive=ProgressiveMode.PROGRESSIVE, 
    compress_level=6
)
with open('test.png', 'wb') as fout:
    fout.write(binary)

CLI Example

There is a CLI included with this distribution.

# turn a numpy file into a highly compressed progressive PNG
pyspng example.npy --level 9 --progressive # -> example.png

# create a highly compressed progressive interlaced PNG
pyspng example.npy --level 9 --interlaced # -> example.png

# convert a PNG into a numpy file example.npy
pyspng -d example.png 

# read header
pyspng --header example.png

Installation

pip install pyspng-seunglab

Binary wheels are built for Linux, MacOS, and Windows. This library is intended to be a drop-in replacement for pyspng, so simultaneous installations are not possible. If this is inconvinient, we can adjust this.

Differences from pyspng

  1. Compiles on MacOS
  2. Upgrades spng to 0.7.2
  3. Fixes a bug for decoding grayscale with alpha
  4. Adds an encoder function (new in libspng)
  5. Replaces zlib with miniz-2.2.0 for simplicity.
  6. Adds CLI for compressing/decompressing npy files.
  7. Adds function for examining PNG headers.

License

pyspng and pyspng-seunglab are provided under a BSD-style license that can be found in the LICENSE file. By using, distributing, or contributing to this project, you agree to the terms and conditions of this license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyspng-seunglab-1.1.0.tar.gz (126.6 kB view hashes)

Uploaded Source

Built Distributions

pyspng_seunglab-1.1.0-cp311-cp311-win_amd64.whl (130.3 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

pyspng_seunglab-1.1.0-cp311-cp311-win32.whl (114.0 kB view hashes)

Uploaded CPython 3.11 Windows x86

pyspng_seunglab-1.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pyspng_seunglab-1.1.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686

pyspng_seunglab-1.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

pyspng_seunglab-1.1.0-cp311-cp311-macosx_10_9_x86_64.whl (202.6 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pyspng_seunglab-1.1.0-cp311-cp311-macosx_10_9_universal2.whl (387.2 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

pyspng_seunglab-1.1.0-cp310-cp310-win_amd64.whl (133.0 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

pyspng_seunglab-1.1.0-cp310-cp310-win32.whl (117.1 kB view hashes)

Uploaded CPython 3.10 Windows x86

pyspng_seunglab-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyspng_seunglab-1.1.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686

pyspng_seunglab-1.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

pyspng_seunglab-1.1.0-cp310-cp310-macosx_10_9_x86_64.whl (202.5 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pyspng_seunglab-1.1.0-cp310-cp310-macosx_10_9_universal2.whl (387.3 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

pyspng_seunglab-1.1.0-cp39-cp39-win_amd64.whl (131.5 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

pyspng_seunglab-1.1.0-cp39-cp39-win32.whl (117.0 kB view hashes)

Uploaded CPython 3.9 Windows x86

pyspng_seunglab-1.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyspng_seunglab-1.1.0-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686

pyspng_seunglab-1.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

pyspng_seunglab-1.1.0-cp39-cp39-macosx_10_9_x86_64.whl (202.7 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pyspng_seunglab-1.1.0-cp39-cp39-macosx_10_9_universal2.whl (381.7 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

pyspng_seunglab-1.1.0-cp38-cp38-win_amd64.whl (132.9 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

pyspng_seunglab-1.1.0-cp38-cp38-win32.whl (117.0 kB view hashes)

Uploaded CPython 3.8 Windows x86

pyspng_seunglab-1.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyspng_seunglab-1.1.0-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686

pyspng_seunglab-1.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

pyspng_seunglab-1.1.0-cp38-cp38-macosx_11_0_universal2.whl (382.0 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ universal2 (ARM64, x86-64)

pyspng_seunglab-1.1.0-cp38-cp38-macosx_10_9_x86_64.whl (202.5 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pyspng_seunglab-1.1.0-cp37-cp37m-win_amd64.whl (133.4 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

pyspng_seunglab-1.1.0-cp37-cp37m-win32.whl (118.0 kB view hashes)

Uploaded CPython 3.7m Windows x86

pyspng_seunglab-1.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

pyspng_seunglab-1.1.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686

pyspng_seunglab-1.1.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

pyspng_seunglab-1.1.0-cp37-cp37m-macosx_10_9_x86_64.whl (201.0 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pyspng_seunglab-1.1.0-cp36-cp36m-win_amd64.whl (133.2 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

pyspng_seunglab-1.1.0-cp36-cp36m-win32.whl (118.0 kB view hashes)

Uploaded CPython 3.6m Windows x86

pyspng_seunglab-1.1.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

pyspng_seunglab-1.1.0-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ i686

pyspng_seunglab-1.1.0-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ ARM64

pyspng_seunglab-1.1.0-cp36-cp36m-macosx_10_9_x86_64.whl (201.0 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page