Skip to main content

Fast & minimal python module to compute the dominant color of an image, written in Rust.

Project description

dominant-color 🔖

Fast & minimal python module to compute the dominant color of an image, written in Rust.

Usage

Pre-compiled binaries are available for Linux using pip :

pip install dominantcolor

Alternatively, you can download wheel directly from releases, or build it yourself.

This module is written in Rust, so it's faster than a pure-python module. Usage is very intuitive :

from dominantcolor import get_dominant_color

# Let's open an image as bytes object.
# This is just for the example, you can use any bytes object that
# correspond to a valid image format (https://crates.io/crates/image#supported-image-formats).
img = open("image.png", "rb").read()

# Now we call the function to compute the dominant color
color = get_dominant_color(img)

# The color is returned as an int, so we convert it to hex to make
# it more readable.
print(hex(color))

If image decoding failed, an dominantcolor.DecodingError exception is raised.

Internally, the module compute the HSL value of each pixel (max. 50k) and classifies each pixel using its hue. The average of the biggest group of pixels is returned.

Build-it yourself

Before you start, ensure Rust is installed on your computer.

$ # Clone the repository
$ git clone https://github.com/baptiste0928/dominant-color.git & cd dominant-color
Cloning into 'dominant-color'...
...

$ # Install maturin (build tool)
$ pip install maturin
...

$ # Build python package
$ maturin build --release
...
📦 Built wheel for CPython 3.8 to ...


Python package (as wheel) can be found at dominant-color/target/wheels/. It can be installed for any project with pip install dominantcolor[...].whl.

Contributing

This is my first real project in Rust, I will be happy to receive contributions to improve it! 🙌 Feel free to open an issue or a PR if you want to contribute.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

dominantcolor-1.0.0-cp39-cp39-manylinux2010_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

dominantcolor-1.0.0-cp38-cp38-manylinux2010_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

dominantcolor-1.0.0-cp37-cp37m-manylinux2010_x86_64.whl (1.4 MB view details)

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

dominantcolor-1.0.0-cp36-cp36m-manylinux2010_x86_64.whl (1.4 MB view details)

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

File details

Details for the file dominantcolor-1.0.0-cp39-cp39-manylinux2010_x86_64.whl.

File metadata

  • Download URL: dominantcolor-1.0.0-cp39-cp39-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.9, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for dominantcolor-1.0.0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 225ae22e676b7c70bf053d311ced919bf2b5e2589e5df456cd5e068f976c0129
MD5 52a7781d4467f0e17743c5b372337e57
BLAKE2b-256 29a1905907b3785692b54a92f429be3fe9e11a60f07fa301e178c4e1e10edb16

See more details on using hashes here.

File details

Details for the file dominantcolor-1.0.0-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

  • Download URL: dominantcolor-1.0.0-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for dominantcolor-1.0.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 356495055117a273d025650503feecfcc189372fa67e43ed32186ea126181edd
MD5 b9764fb1a994038bcd9d0193d16b485e
BLAKE2b-256 518e823b07fee4f6bc9ee9dae329fcd9eb9874d4b06ca6dcf302613e6be65d42

See more details on using hashes here.

File details

Details for the file dominantcolor-1.0.0-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: dominantcolor-1.0.0-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for dominantcolor-1.0.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 a075ff0b53597b9910c8848287ff7b9ba1d326b7614427d37815d57f16473f23
MD5 0a1c51a4e67d6dc1da4cd16a3047d272
BLAKE2b-256 0e833b745efd0b52fad5740c052814000782654753faa0f94c07f0757e3f5bb6

See more details on using hashes here.

File details

Details for the file dominantcolor-1.0.0-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: dominantcolor-1.0.0-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for dominantcolor-1.0.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 60d159a549ff078f8680722cfefb3e60b157ba315e4ccf2d3d477d9c9554595c
MD5 68f9c56ff453f5f0930faafe0dc09fe1
BLAKE2b-256 cb1968462e2043bc2f94efa146bc0ea9aeb7c16ae1c688e42c44831ebd6d8bf8

See more details on using hashes here.

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