imagequant

Python bindings for libimagequant

https://github.com/wanadev/imagequant-python

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.4%) to scientific vocabulary

Keywords from Contributors

transformers interactive serializer packaging network-simulation shellcodes hacking autograding observability genomics
Last synced: 10 months ago · JSON representation

Repository

Python bindings for libimagequant

Basic Info
  • Host: GitHub
  • Owner: wanadev
  • Language: Python
  • Default Branch: master
  • Size: 136 KB
Statistics
  • Stars: 20
  • Watchers: 5
  • Forks: 4
  • Open Issues: 1
  • Releases: 7
Created almost 5 years ago · Last pushed 11 months ago
Metadata Files
Readme License

README.rst

Imagequant Python - Python Bindings for libimagequant
=====================================================

|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.

.. _libimagequant: https://github.com/ImageOptim/libimagequant


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
~~~~~~~~~~~~~~~~~

.. code-block:: python

    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
        min_quality=0,        # from 0 to 100
        max_quality=100,      # from 0 to 100
    )
    output_image.save("./out.png", format="PNG")

|input_image| → |output_image|

.. |input_image| image:: ./example.png
.. |output_image| image:: ./example_out.png


With Raw Data
~~~~~~~~~~~~~

.. code-block:: python

    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
        min_quality=0,        # from 0 to 100
        max_quality=100,      # from 0 to 100
    )

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

Example ``output_image_data``:

.. code-block:: python

    b'\x02\x03\x00\x01'

Example ``output_palette``:

.. code-block:: python

    [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.

.. _LICENSE: https://github.com/wanadev/imagequant-python/blob/master/LICENSE


Changelog
---------

* **[NEXT]** (changes on ``master`` that have not been released yet):

  * Nothing yet ;)

* **v1.1.4:**

  * fix: Cleanup before throwing RuntimeError to avoid memory leak (@laggykiller, #26)

* **v1.1.3:**

  * misc(deps): Fixed PyPy builds on Windows platform (@flozz)

* **v1.1.2:**

  * misc: Removed PyPy wheels for Windows AMD64 as they won't build (@flozz)
  * misc: Fixed libimagequant build on newer GCC versions (@flozz)
  * misc: Added Python 3.13 support (@flozz)
  * misc!: Removed Python 3.8 support (@flozz)

* **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 support

* **v1.0.3:**

  * ``arm64`` and ``universal2`` wheels for macOS M1
  * ``x86`` and ``x68_64`` wheels for musl-based Linux distro (Alpine,...)
  * ``x86`` wheels for Windows (``x86_64`` were already available)

* **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.



.. |Github| image:: https://img.shields.io/github/stars/wanadev/imagequant-python?label=Github&logo=github
   :target: https://github.com/wanadev/imagequant-python
.. |Discord| image:: https://img.shields.io/badge/chat-Discord-8c9eff?logo=discord&logoColor=ffffff
   :target: https://discord.gg/BmUkEdMuFp
.. |PYPI Version| image:: https://img.shields.io/pypi/v/imagequant.svg
   :target: https://pypi.python.org/pypi/imagequant
.. |Build Status| image:: https://github.com/wanadev/imagequant-python/actions/workflows/python-ci.yml/badge.svg
   :target: https://github.com/wanadev/imagequant-python/actions
.. |Black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
   :target: https://black.readthedocs.io/en/stable/
.. |License| image:: https://img.shields.io/pypi/l/imagequant.svg
   :target: https://github.com/wanadev/imagequant-python/blob/master/LICENSE

Owner

  • Name: Wanadev
  • Login: wanadev
  • Kind: organization
  • Location: Lyon, France

GitHub Events

Total
  • Release event: 3
  • Watch event: 4
  • Delete event: 11
  • Issue comment event: 1
  • Push event: 18
  • Pull request event: 17
  • Fork event: 1
  • Create event: 12
Last Year
  • Release event: 3
  • Watch event: 4
  • Delete event: 11
  • Issue comment event: 1
  • Push event: 18
  • Pull request event: 17
  • Fork event: 1
  • Create event: 12

Committers

Last synced: over 1 year ago

All Time
  • Total Commits: 76
  • Total Committers: 5
  • Avg Commits per committer: 15.2
  • Development Distribution Score (DDS): 0.355
Past Year
  • Commits: 19
  • Committers: 2
  • Avg Commits per committer: 9.5
  • Development Distribution Score (DDS): 0.421
Top Committers
Name Email Commits
Fabien LOISON f****o@f****m 49
dependabot[bot] 4****] 18
laggykiller c****2@g****m 6
injet-zhou i****u@u****n 2
faddddeout 3****u 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 2
  • Total pull requests: 27
  • Average time to close issues: about 1 month
  • Average time to close pull requests: 1 day
  • Total issue authors: 2
  • Total pull request authors: 3
  • Average comments per issue: 3.0
  • Average comments per pull request: 0.19
  • Merged pull requests: 25
  • Bot issues: 0
  • Bot pull requests: 24
Past Year
  • Issues: 0
  • Pull requests: 13
  • Average time to close issues: N/A
  • Average time to close pull requests: 1 day
  • Issue authors: 0
  • Pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 0.15
  • Merged pull requests: 12
  • Bot issues: 0
  • Bot pull requests: 12
Top Authors
Issue Authors
  • laggykiller (1)
  • anthrotype (1)
  • dependabot[bot] (1)
Pull Request Authors
  • dependabot[bot] (43)
  • laggykiller (3)
  • injet-zhou (1)
Top Labels
Issue Labels
enhancement (1) dependencies (1)
Pull Request Labels
dependencies (43) github_actions (11)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 5,542 last-month
  • Total dependent packages: 2
  • Total dependent repositories: 2
  • Total versions: 11
  • Total maintainers: 2
pypi.org: imagequant

Image Quantization Library

  • Versions: 11
  • Dependent Packages: 2
  • Dependent Repositories: 2
  • Downloads: 5,542 Last month
Rankings
Dependent packages count: 4.8%
Downloads: 7.7%
Dependent repos count: 11.5%
Average: 12.2%
Stargazers count: 17.7%
Forks count: 19.1%
Maintainers (2)
Last synced: 11 months ago

Dependencies

setup.py pypi
  • cffi >=1.0.0
.github/workflows/python-ci.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v5 composite
.github/workflows/python-packages.yml actions
  • actions/checkout v4 composite
  • actions/download-artifact v3 composite
  • actions/setup-python v5 composite
  • actions/upload-artifact v3 composite
  • pypa/cibuildwheel v2.16.2 composite
  • pypa/gh-action-pypi-publish release/v1 composite