Okmain: OK main colors (Python edition)
okmain finds the main colors of an image and makes sure they look good.
Docs • PyPI Package • GitHub • Rust crate
Sometimes you need to show a "dominant" color (or colors) of an image. It can be a background or a placeholder. There are several ways of doing that; a popular quick-and-dirty method is to resize the image to a handful of pixels, or even just one.
However, this method tends to produce muted, dirty-looking colors. Most images have clusters of colors: the dominant colors of an image of a lush green field with a clear sky above it are not a muddy average of blue and green, it's a bright blue and green. Okmain clusters colors explicitly, recovering and ranking main colors while keeping them sharp and clean.
Here's a comparison:
Technical highlights
- Color operations in a state-of-the-art perceptually linear color space (Oklab)
- Rust implementation for speed and safety
- Finding main colors of a reasonably sized image takes about 100ms
- Fast custom K-means color clustering, optimized for auto-vectorization (confirmed with disassembly)
- Position- and visual prominence-based color prioritization (more central and higher Oklab chroma pixels tend to be more important)
- Tunable parameters (see optional kwargs on
colors)
Read more about Okmain in the blog post.
Usage
Install the package:
uv add okmain
Call okmain.colors() on a PIL/Pillow image to get back a list of RGB colors:
import okmain
from PIL import Image
test_image = Image.open("test_image.jpeg")
dominant_colors = okmain.colors(test_image)
# dominant_colors are [okmain.RGB(r=..., g=..., b=...), ...)
css_hex = dominant_colors[0].to_hex()
# css_hex is a string like "#AABBCC"
Metadata
Release files for okmain 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| okmain-0.4.0.tar.gz | 29.4 kB | Without provenance | Details for okmain-0.4.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| okmain-0.4.0-cp312-abi3-musllinux_1_2_x86_64.whl | CPython 3.12 | abi3 | Linux musl 1.2+ x86-64 | Details for okmain-0.4.0-cp312-abi3-musllinux_1_2_x86_64.whl |
| okmain-0.4.0-cp312-abi3-musllinux_1_2_aarch64.whl | CPython 3.12 | abi3 | Linux musl 1.2+ ARM64 | Details for okmain-0.4.0-cp312-abi3-musllinux_1_2_aarch64.whl |
| okmain-0.4.0-cp312-abi3-manylinux_2_28_x86_64.whl | CPython 3.12 | abi3 | Linux glibc 2.28+ x86-64 | Details for okmain-0.4.0-cp312-abi3-manylinux_2_28_x86_64.whl |
| okmain-0.4.0-cp312-abi3-manylinux_2_28_aarch64.whl | CPython 3.12 | abi3 | Linux glibc 2.28+ ARM64 | Details for okmain-0.4.0-cp312-abi3-manylinux_2_28_aarch64.whl |
| okmain-0.4.0-cp312-abi3-macosx_11_0_arm64.whl | CPython 3.12 | abi3 | macOS 11.0+ ARM64 | Details for okmain-0.4.0-cp312-abi3-macosx_11_0_arm64.whl |
| okmain-0.4.0-cp312-abi3-macosx_10_12_x86_64.whl | CPython 3.12 | abi3 | macOS 10.12+ x86-64 | Details for okmain-0.4.0-cp312-abi3-macosx_10_12_x86_64.whl |
Total release size: 2.0 MB
Release files / okmain-0.4.0.tar.gz
| Download URL | okmain-0.4.0.tar.gz |
|---|---|
| Size | 29.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c21e32a4196650768529b8640f29854cb0caa421994e3910e9231790fb80da1e
|
|
BLAKE2b-256 checksum How to use checksums |
8a02f2ff10d923f6f3e7f79291bbfa85ec3b886ac4c5296bf9fda527ef452dc1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / okmain-0.4.0-cp312-abi3-musllinux_1_2_x86_64.whl
| Download URL | okmain-0.4.0-cp312-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 478.8 kB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
f8d50ae6990bcb51957bfb007d1fa956efac445b0538064c77b6077989a5ebe1
|
|
BLAKE2b-256 checksum How to use checksums |
c97de4a48c27f950ae83d80ea38502cbc7a4ad2c613a6aa3fac1a8f5260ebbbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / okmain-0.4.0-cp312-abi3-musllinux_1_2_aarch64.whl
| Download URL | okmain-0.4.0-cp312-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 439.4 kB |
| Tags | CPython 3.12 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
4f5296627779dd5f3117621928c33af50af648e4a34a398ec5076a48218e1cef
|
|
BLAKE2b-256 checksum How to use checksums |
04e9b853f17c68c55d46c11572f92ef3a308d41cb576ced574ae237e86d855c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / okmain-0.4.0-cp312-abi3-manylinux_2_28_x86_64.whl
| Download URL | okmain-0.4.0-cp312-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 267.8 kB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
3e12e426887f154d1f9d09334b3bf794694297c99825f9b47241a2624f40ca31
|
|
BLAKE2b-256 checksum How to use checksums |
b34d37425137763c11d84be8e51c7ede5e48a41ad4a310f4c5fb9255f8b1ac60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / okmain-0.4.0-cp312-abi3-manylinux_2_28_aarch64.whl
| Download URL | okmain-0.4.0-cp312-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 262.1 kB |
| Tags | CPython 3.12 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
1f3b24a361f8fe981e75b8de593b402b1cbf22c1175b941d9db745e1a416eab4
|
|
BLAKE2b-256 checksum How to use checksums |
eebb0145c80fe6e76b42f74d68cdc43d004425b59771344312680e3a22465367
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / okmain-0.4.0-cp312-abi3-macosx_11_0_arm64.whl
| Download URL | okmain-0.4.0-cp312-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 240.3 kB |
| Tags | CPython 3.12 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
377b56918b77e77eec93bcdc1ef7b675155b79fa24154a9a655cebf9197742d0
|
|
BLAKE2b-256 checksum How to use checksums |
5fe3fd8abae3aa2c51a7447ef53a19cb05f6236dcb35a5184acc190220b5539b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / okmain-0.4.0-cp312-abi3-macosx_10_12_x86_64.whl
| Download URL | okmain-0.4.0-cp312-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 249.8 kB |
| Tags | CPython 3.12 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
7159d52886eb2f196c542c03cc1976f1936416bbc594d1b1078a6c2018bb8632
|
|
BLAKE2b-256 checksum How to use checksums |
bbad275ac138575e672672f4339170f016ad259de80fb4da4d4cfdf53c62629f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for okmain 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.