No project description provided
Project description
pyoxipng
Python wrapper for multithreaded .png image file optimizer
oxipng (written in Rust). Use
pyoxipng
to reduce the file size of your PNG images.
Installation
Install from PyPI:
pip install pyoxipng
Import in your Python code:
import oxipng
Usage
To optimize an existing file on disk:
oxipng.optimize("/path/to/image.png", "/path/to/image-optimized.png")
Second argument is optional; if not provided, will overwrite the existing file.
To optimize a file already-loaded in Python as a bytes
object:
data = ... # bytes of png data
optimized_data = oxipng.optimize_from_memory(data)
# Save the result
with open("/path/to/image-optimized.png", "wb") as f:
f.write(optimized_data)
Both functions raise oxipng.PngError
if the optimization cannot be completed.
Options
Both the optimize
and optimize_from_memory
functions take the following
options as keyword arguments.
Example usage:
oxipng.optimize("/path/to/image.png", level=6, backup=True, interlace=1)
Option | Description | Type | Default |
---|---|---|---|
level |
Set the optimization level to an integer between 0 and 6 (inclusive) | int |
2 |
backup |
Whether the input file should be backed up before writing the output | bool |
False |
fix_errors |
Attempt to fix errors when decoding the input file rather than throwing PngError |
bool |
False |
pretend |
Don't actually write any output file, just calculate the best results | bool |
False |
force |
Write to output even if there was no improvement in compression | bool |
False |
preserve_attrs |
Ensure the output file has the same permissions as the input file | bool |
False |
filter |
Which filters to try on the file [0-5] | set[int] |
{0,5} |
interlace |
Whether to change the interlacing type of the file. 0 means disable interlacing. 1 means enable it. None means leave as is. |
int | None |
None |
bit_depth_reduction |
Whether to attempt bit depth reduction | bool |
True |
color_type_reduction |
Whether to attempt color type reduction | bool |
True |
palette_reduction |
Whether to attempt palette reduction | bool |
True |
grayscale_reduction |
Whether to attempt grayscale reduction | bool |
True |
idat_recoding |
If any type of reduction is performed, IDAT recoding will be performed regardless of this setting | bool |
True |
use_heuristics |
Whether to use heuristics to pick the best filter and compression. Intended for use with level=1 |
bool |
False |
timeout |
Maximum amount of time to spend (in milliseconds) on optimizations. Further potential optimizations are skipped if the timeout is exceeded. | int | None |
None |
Development
- Install Rust
- Install Python 3.7+
- Install Pipenv
- Clone this repository and navigate to it via command line
git clone https://github.com/nfrasser/pyoxipng.git cd pyoxipng
- Install dependencies
pipenv install --dev
- Activate the dev environment
pipenv shell
- Build
maturin develop
- Run tests
pytest
- Format code
black .
License
MIT
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
pyoxipng-0.1.0.tar.gz
(293.9 kB
view hashes)
Built Distributions
Close
Hashes for pyoxipng-0.1.0-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81bc5791b73f35646097518801983378c1566705e76715fb5bca43a5d4047a97 |
|
MD5 | 8b984367717e37ea0f6a096ed2bb845d |
|
BLAKE2b-256 | b29e11b21106067c32e16dae7ecea73263c244a83c9c19148a67c4e26e407d42 |
Close
Hashes for pyoxipng-0.1.0-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2ac53b9afcecbd53c68bb80db0acc1910cf74b742cc41b81b517f44d50a9c62 |
|
MD5 | 3c07ed9574d3cb012d4d25ed0d9d4b00 |
|
BLAKE2b-256 | 0b7bf27927592bf1c55f2822f9492679ef81f0b3e7b508c6dcc31cb4c4e94897 |
Close
Hashes for pyoxipng-0.1.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db2b80931cd2503ffd6be0b29aa0bb121e7210dfed7db740e06ff4e6e3e172e4 |
|
MD5 | 7222c294c720f2f5fa85cc16bc42df0c |
|
BLAKE2b-256 | 5dc26ad113c39ca11bf4fe95fff2857a82c87b5b7f92f9339f8d8ce6a6094f83 |
Close
Hashes for pyoxipng-0.1.0-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e84566800ce0b35257c6e004b34f3e9a3f1a8c06c636022bdeff0bfc5aa27b7 |
|
MD5 | f4d97c4a75fa32f2de27b9f6a2c92fb1 |
|
BLAKE2b-256 | 3d593c167d40405f51a8dbba63b65d212f0e7608c57495d2bb0b28d0d9a75b7d |
Close
Hashes for pyoxipng-0.1.0-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67be239372487890118df9fda3dbc42ae765a610077e30c2eede70a8fe636663 |
|
MD5 | 160504e7165350f1d8f5aa72235e5b81 |
|
BLAKE2b-256 | 6d97b2278e3e1896b2604302ddecb36007184bfba5132d6de83df6d6f8194915 |
Close
Hashes for pyoxipng-0.1.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64fe2d6bf5de409d425d4b1a88ce636776cb852977c2b1a7347e350ce7db88de |
|
MD5 | a77b2dad561ff939f88b8549854f0ccb |
|
BLAKE2b-256 | cb1315cbaad71ac82a16c52037c530e11eac8e3955d383a9924b2cb51e0de717 |
Close
Hashes for pyoxipng-0.1.0-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f9b63230a2ff4018786c39d6f2c2c010d6833e6ee0e49feeeec3f4d8ef14a17 |
|
MD5 | 3d8a74eaa49d58f40d135b2ec4347a74 |
|
BLAKE2b-256 | 8f72b22d53ad0094caabcac5ec66da6c365ea32868c16d845b643b831d1497e1 |
Close
Hashes for pyoxipng-0.1.0-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5e631474d4a619e8b383731bca66724cbc511915fcb3dfb82dfb6c70cdb143b |
|
MD5 | 771071cddfdae9b6855301e3c504bcd1 |
|
BLAKE2b-256 | 599a566b3570df9915a8ef3e283197fdc8923d39084f8bc98a39238b57a78508 |
Close
Hashes for pyoxipng-0.1.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b4fa3e7d520540019409fdf39950434f15244fa34c354ae0eabad4d0f1987ec |
|
MD5 | 654bd92b9666b7d90c5d1deec323b984 |
|
BLAKE2b-256 | 7b3775b329237836f463992c51402d5d33f3f707a0476e8f725907d340436d44 |
Close
Hashes for pyoxipng-0.1.0-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | abe7f96604e3dc4bc370195235cfb7a2c3e46192cec808a195c2235d4ce9718d |
|
MD5 | 1e7ed59798564e8c460e0cdc79834096 |
|
BLAKE2b-256 | d68e90bb14ba9c51a796bf096fb35de00e71e763adc147395da6dbe90baf683f |
Close
Hashes for pyoxipng-0.1.0-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb91b6cd635d87e57ca4a5428d6b81af314b4c4f7e83f4d8ae7c8e391acd1270 |
|
MD5 | 3c6373b91cc23a75880009ea8e7dfaba |
|
BLAKE2b-256 | eadf08592493bed038018fd04f6d80309a4d1f6a2caa636430fafff1bfa7d6a9 |
Close
Hashes for pyoxipng-0.1.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39c3287a7a94ebb91322b41d844fc41ae8710005b7aae095ce334a080adbed7d |
|
MD5 | 6057051cd76f8afc01ffc4600981d465 |
|
BLAKE2b-256 | 85485e2be32251ce208b2c1518007d1c62a5b35733d9f863cbe951ded81b41a6 |
Close
Hashes for pyoxipng-0.1.0-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9aa53111b6a5aac154a848bccb5e9a996ee8adb095a13d2da4e0561f283b5761 |
|
MD5 | d0d5fb518fec50c7d2e1e85845bf6f04 |
|
BLAKE2b-256 | d9e40c8c1cbf0ae75dbf9bf83868086ddde93e84880b256956b7f23e8047b090 |