Skip to main content

Image Quantization Library

Project description

Github Discord PYPI Version Build Status Black License

Imagequant Python are bindings to allow using libimagequant from Python.

Libimagequant is a small, portable C library for high-quality conversion of RGBA images to 8-bit indexed-color (palette) images.

Install

From PyPI:

pip3 install imagequant

NOTE: you may require compilation tools to build the library if you system is not suitable for the precompiled wheels. On Debian / Ubuntu you can install the build dependencies with the following command:

sudo apt install build-essential python3-dev

Usage

With PIL / Pillow

from PIL import Image
import imagequant

input_image = Image.open("./example.png")
output_image = imagequant.quantize_pil_image(
    input_image,
    dithering_level=1.0,  # from 0.0 to 1.0
    max_colors=256,       # from 1 to 256
)
output_image.save("./out.png", format="PNG")

input_imageoutput_image

With Raw Data

import imagequant

# 2×2px image
IMAGE_DATA = (
    # | R | G | B | A |
    b"\xFF\x00\x00\xFF"  # red
    b"\x00\xFF\x00\xFF"  # lime
    b"\x00\x00\xFF\xFF"  # blue
    b"\xFF\xFF\xFF\xFF"  # white
)

output_image_data, output_palette = imagequant.quantize_raw_rgba_bytes(
    IMAGE_DATA,           # RGBA image data
    2, 2,                 # width, height
    dithering_level=1.0,  # from 0.0 to 1.0
    max_colors=256,       # from 1 to 256
)

# you can now encode image data and the palette in any image format...

Example output_image_data:

b'\x02\x03\x00\x01'

Example output_palette:

[0, 0, 255, 255, 255, 255, 255, 255, 255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 0, 0, ...]
# color 0      | color 1           | color 2       | color 3       | color 4   | ...

Development of the Bindings

Clone the repository and get the submodules:

git clone https://github.com/wanadev/imagequant-python.git
cd imagequant-python
git submodule init
git submodule update

Install some dependencies (preferably in a virtualenv):

pip3 install nox cffi pillow

Build the binary part of the lib:

python imagequant/libimagequant_build.py

A .so file (or a .pyd file on Windows, or a .dylib file on MacOS) shoud now be present in the imagequant/ folder. You will not need to run this command again until you change something in imagequant/libimagequant.h or in libimagequant/*.{c,h}.

To check the coding style, you can run the lint with the following command:

nox -s lint

To run the tests, use the following command:

nox -s test

License

Imagequant Python is licensed under the BSD 3 Clause. See the LICENSE file for more information.

Libimagequant is dual-licensed:

  • For Free/Libre Open Source Software it’s available under GPL v3 or later with additional copyright notices for older parts of the code.

  • For use in closed-source software, AppStore distribution, and other non-GPL uses, you can obtain a commercial license.

Read its license terms for more information.

Changelog

  • v1.0.2: Python 3.10 support and wheels

  • v1.0.1: Fix encoding while reading the README in setup.py

  • v1.0.0: Initial release with a minimal API.

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

imagequant-1.0.2.tar.gz (63.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

imagequant-1.0.2-cp310-cp310-win_amd64.whl (54.5 kB view details)

Uploaded CPython 3.10Windows x86-64

imagequant-1.0.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (193.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.12+ x86-64manylinux: glibc 2.5+ x86-64

imagequant-1.0.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (170.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.12+ i686manylinux: glibc 2.5+ i686

imagequant-1.0.2-cp310-cp310-macosx_10_14_x86_64.whl (55.1 kB view details)

Uploaded CPython 3.10macOS 10.14+ x86-64

imagequant-1.0.2-cp39-cp39-win_amd64.whl (54.5 kB view details)

Uploaded CPython 3.9Windows x86-64

imagequant-1.0.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (193.4 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.12+ x86-64manylinux: glibc 2.5+ x86-64

imagequant-1.0.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (170.7 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.12+ i686manylinux: glibc 2.5+ i686

imagequant-1.0.2-cp39-cp39-macosx_10_14_x86_64.whl (55.1 kB view details)

Uploaded CPython 3.9macOS 10.14+ x86-64

imagequant-1.0.2-cp38-cp38-win_amd64.whl (54.5 kB view details)

Uploaded CPython 3.8Windows x86-64

imagequant-1.0.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (193.8 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.12+ x86-64manylinux: glibc 2.5+ x86-64

imagequant-1.0.2-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (171.1 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.12+ i686manylinux: glibc 2.5+ i686

imagequant-1.0.2-cp38-cp38-macosx_10_14_x86_64.whl (55.1 kB view details)

Uploaded CPython 3.8macOS 10.14+ x86-64

imagequant-1.0.2-cp37-cp37m-win_amd64.whl (54.5 kB view details)

Uploaded CPython 3.7mWindows x86-64

imagequant-1.0.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (193.1 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.12+ x86-64manylinux: glibc 2.5+ x86-64

imagequant-1.0.2-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (170.3 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.12+ i686manylinux: glibc 2.5+ i686

imagequant-1.0.2-cp37-cp37m-macosx_10_14_x86_64.whl (55.1 kB view details)

Uploaded CPython 3.7mmacOS 10.14+ x86-64

File details

Details for the file imagequant-1.0.2.tar.gz.

File metadata

  • Download URL: imagequant-1.0.2.tar.gz
  • Upload date:
  • Size: 63.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for imagequant-1.0.2.tar.gz
Algorithm Hash digest
SHA256 438e61cbd13fbbc0628790e693314a019e7a27ea176acf570ef8aa47723aed6a
MD5 9c98e35f71927f5ad966d7e121ab3608
BLAKE2b-256 bff7891f328c089e884a4c4dcc954e673d719f879da43e24fe3bdd4ca396a670

See more details on using hashes here.

File details

Details for the file imagequant-1.0.2-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: imagequant-1.0.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 54.5 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for imagequant-1.0.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a53796b4db5a1afa2858a6b223d4f89856b834aa2b106ba8794f2ffcf3aa6893
MD5 c00e36aa36d9a27edcb96e16102a3983
BLAKE2b-256 4cde98fd2fdadb524e783659172a2af3708cee447e76b023eb4af7bb6f7ff915

See more details on using hashes here.

File details

Details for the file imagequant-1.0.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for imagequant-1.0.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 fcc24fca7a0d2f1ec9d6c3cdd95cb015526e193b2b25e720d50767ccdd6a7994
MD5 881211c14f2e84ee0e5b822e2aa2c0e5
BLAKE2b-256 9940622ccce231d789fc2ba9c5f6377f757e778c6a10fd70dadcc8b2ded4c7d0

See more details on using hashes here.

File details

Details for the file imagequant-1.0.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl.

File metadata

File hashes

Hashes for imagequant-1.0.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 057f8b5543b20b5dd75f657ed9955a7ef5a7d0ba4acc99998271fb9c748338a3
MD5 95416a92f03c23d957c924542d61b6c4
BLAKE2b-256 0ff7323446c012a4bed77bd5a9d6bf350db9a5f2a8334b1662ff5680648deb25

See more details on using hashes here.

File details

Details for the file imagequant-1.0.2-cp310-cp310-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: imagequant-1.0.2-cp310-cp310-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 55.1 kB
  • Tags: CPython 3.10, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for imagequant-1.0.2-cp310-cp310-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 1ab43f23b23e2009a0cd85a2dc2dee78d6cd5a46a60089a9602f2e098c20af6b
MD5 eeda22233c3cf14145a06161102464d6
BLAKE2b-256 257af03ad24bdb6a52cb53dea7bc35c8cc24eaa4571836c047222c39d854dde8

See more details on using hashes here.

File details

Details for the file imagequant-1.0.2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: imagequant-1.0.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 54.5 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for imagequant-1.0.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 a47c95966b6d4aae3e798a712d803be8bcae7fa7117669223e649f9bb54f806f
MD5 7f823955c40844bc25eae6680f2a7352
BLAKE2b-256 2d6d631da59c5e94b300246c148d5d58e86d312a8d5d13f9b1650117b4139bfa

See more details on using hashes here.

File details

Details for the file imagequant-1.0.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for imagequant-1.0.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 26603d4858f8f470ee44e0981ca5117e49fd41b519a91f7db2637ba1bbaac12c
MD5 ad44d83c6447ce3eb5840ae6fc21fe8b
BLAKE2b-256 806fbcdbe12db1fd6a2409be712a4709de97f2626595f2dc3037f459b7ff8e24

See more details on using hashes here.

File details

Details for the file imagequant-1.0.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl.

File metadata

File hashes

Hashes for imagequant-1.0.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 637b3f4a36df636e90422ae9684471502334ef2ae53ac2b10588204cd63d2f2b
MD5 f0030669e6c90027715026c360b4139a
BLAKE2b-256 a0114e98c5c0c7cf17dbce4ae1e6dd6806185bea2b7673d09ae19bbe18b98860

See more details on using hashes here.

File details

Details for the file imagequant-1.0.2-cp39-cp39-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: imagequant-1.0.2-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 55.1 kB
  • Tags: CPython 3.9, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for imagequant-1.0.2-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 9307d66e91a3483b16d12f93ff4a96b237d4ee9d4d019deb27a3cf226cfa694c
MD5 761dfbf0c6d18f2719610846fb5c6bfe
BLAKE2b-256 875300cad62796965b85dc07c0d9312697360ba636bfe63a6317a9e028ab4e13

See more details on using hashes here.

File details

Details for the file imagequant-1.0.2-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: imagequant-1.0.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 54.5 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for imagequant-1.0.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 13d96ad8117402e3bad0661e523373708fe74029ada92635888e180771ba9cb3
MD5 3ed373d6afaaf2afb99f15b15248c31a
BLAKE2b-256 dd1d59add0de9ccd9c538770151f29898b44008f0067e1260075a738c9f4f493

See more details on using hashes here.

File details

Details for the file imagequant-1.0.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for imagequant-1.0.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 c1a45885c25ba9b91e0397d96f463ecc43547993a4bdcd5efed4168a14a0b316
MD5 b34add7961fa456695c6552f0df49d79
BLAKE2b-256 5511bb9e81952199ca838be7437bd6285ed7e9bbf4cc6f8764d0cab4998c3fc2

See more details on using hashes here.

File details

Details for the file imagequant-1.0.2-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl.

File metadata

File hashes

Hashes for imagequant-1.0.2-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 e73e947155d61dacc3fdfd11066df5dcc66a01f30d39201411343ea9b845527f
MD5 00fa4971aa5cb79bc681749ba287c7d3
BLAKE2b-256 a8e44f91d5b1e9691c34ccf08994fc267f79bb6af80dcacb9289e2ed97d3e794

See more details on using hashes here.

File details

Details for the file imagequant-1.0.2-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: imagequant-1.0.2-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 55.1 kB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for imagequant-1.0.2-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 57c945bc390c7dd0cd842712b802eff102271a175c6f9a14db326a50c5d0e3c8
MD5 8a2127463ecfb5a35e247e58f73531f6
BLAKE2b-256 7d75cdb00484abc1c425897e7fc5b1b504c62416a78e24ab338d2cb5b57f9193

See more details on using hashes here.

File details

Details for the file imagequant-1.0.2-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: imagequant-1.0.2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 54.5 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for imagequant-1.0.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 fecc400a9cbc3a5068195179aca115bf7fc326794eb10b7eb6d32af072e7d35b
MD5 64f45dce32745cdb21af181a5bacc6d5
BLAKE2b-256 982f7430ce6b5e83662b52fa23e8015ea2ea8df5d896c9a4ad0c053d8a77ca3b

See more details on using hashes here.

File details

Details for the file imagequant-1.0.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for imagequant-1.0.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 8ba3b1acfb4af084af9f495c70c0bc0abd14690553fd0df6347a8910ef5b38bc
MD5 4f2255986f8fc3192616cc5cd5490f45
BLAKE2b-256 d9c53b87242d5b30c801955ece22c0ccfb76e303229fa0e1872eec3bdeb60506

See more details on using hashes here.

File details

Details for the file imagequant-1.0.2-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl.

File metadata

File hashes

Hashes for imagequant-1.0.2-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 d8e523b8c3564072758f33f8968e01b8fe6dd99039be9cd8d4141dcb237f893d
MD5 08277a8e92790870106443e38ea43513
BLAKE2b-256 148f3a944a1f31bdbe044113af316047017ff219b2717594851eda085b8dc777

See more details on using hashes here.

File details

Details for the file imagequant-1.0.2-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: imagequant-1.0.2-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 55.1 kB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for imagequant-1.0.2-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 fe94274f5126d8f7ba2ee79ac338eaf4a9e25ed5be3525d9454744c0b99c217f
MD5 09423b29ab82f6657fdfcba40756287a
BLAKE2b-256 f14070e427eb9d73d6085ab2cfebf7701bea521b59598d92d457b41e6b502462

See more details on using hashes here.

Supported by

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