Package: imagequant
Imagequant Pythonare bindings to allow usinglibimagequantfrom Python.Libimagequantis a small, portable C library for high-quality conversion of RGBA images to 8-bit indexed-color (palette) images.InstallFrom PyPI:pip3 install imagequantNOTE: 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-devUsageWith PIL / PillowfromPILimportImageimportimagequantinput_image=Image.open("./example.png")output_image=imagequant.quantize_pil_image(input_image,dithering_level=1.0,# from 0.0 to 1.0max_colors=256,# from 1 to 256min_quality=0,# from 0 to 100max_quality=100,# from 0 to 100)output_image.save("./out.png",format="PNG")→With Raw Dataimportimagequant# 2×2px imageIMAGE_DATA=(# | R | G | B | A |b"\xFF\x00\x00\xFF"# redb"\x00\xFF\x00\xFF"# limeb"\x00\x00\xFF\xFF"# blueb"\xFF\xFF\xFF\xFF"# white)output_image_data,output_palette=imagequant.quantize_raw_rgba_bytes(IMAGE_DATA,# RGBA image data2,2,# width, heightdithering_level=1.0,# from 0.0 to 1.0max_colors=256,# from 1 to 256min_quality=0,# from 0 to 100max_quality=100,# from 0 to 100)# you can now encode image data and the palette in any image format...Exampleoutput_image_data:b'\x02\x03\x00\x01'Exampleoutput_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 BindingsClone the repository and get the submodules:git clone https://github.com/wanadev/imagequant-python.git
cd imagequant-python
git submodule init
git submodule updateInstall some dependencies (preferably in a virtualenv):pip3 install nox cffi pillowBuild the binary part of the lib:python imagequant/libimagequant_build.pyA.sofile (or a.pydfile on Windows, or a.dylibfile on MacOS) shoud now be present in theimagequant/folder. You will not need to run this command again until you change something inimagequant/libimagequant.hor inlibimagequant/*.{c,h}.To check the coding style, you can run the lint with the following command:nox -s lintTo run the tests, use the following command:nox -s testLicenseImagequant Pythonis licensed under the BSD 3 Clause. See theLICENSEfile for more information.Libimagequantis 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 itslicense termsfor more information.Changelog[NEXT](changes onmasterthat have not been released yet):Nothing yet ;)v1.1.1:dist: Build and publish arm64 wheels for Linux and Windows (@laggykiller, #9, #10)v1.1.0:Added options to set minimal and target (maximal) quality (@injet-zhou, #4)v1.0.5:Added Python 3.12 support (@flozz)Removed Python 3.7 support (@flozz)v1.0.4:Added Python 3.11 supportv1.0.3:arm64anduniversal2wheels for macOS M1x86andx68_64wheels for musl-based Linux distro (Alpine,…)x86wheels for Windows (x86_64were already available)v1.0.2:Python 3.10 support and wheelsv1.0.1:Fix encoding while reading the README in setup.pyv1.0.0:Initial release with a minimal API.