Extract dominant colors, generate PNG palettes, JSON exports, and name colors using custom palettes.
Project description
🎨 Color Palette Extractor
A modern Python package for extracting dominant colors from images, generating PNG palette previews, exporting color data to JSON, and naming colors using any custom palette (e.g., Pantone, Material, Brand palettes).
Version 1.2.0
This package includes:
- Dominant color extraction using K-Means
- Color dominance percentages — each color includes its share of the image pixels
- Colors sorted by dominance (most dominant first)
- Optional filtering of near-white and/or near-black pixels before extraction
- RGB or HEX output
- PNG color palette image generation
- JSON export with dominance data
- Optional color naming using custom palettes (Pantone-compatible if you provide the licensed palette)
- Command-line interface (
colorpalette) - Clean import API for integration in other scripts
Installation
pip install color-palette-extractor
CLI Usage
colorpalette input.jpg --colors 5 --format hex --json palette.json --png palette.png
Filtering white and black
colorpalette input.jpg --ignore-white --ignore-black --json palette.json
Custom thresholds (default: white=240, black=15):
colorpalette input.jpg --ignore-white --white-threshold 220 --ignore-black --black-threshold 20
Color Naming
Provide a custom palette JSON:
colorpalette input.jpg --name-colors --palette pantone.json
Python Usage
from color_palette_extractor import extract_palette, save_palette_json
# Basic usage
colors, names, dominance = extract_palette("image.jpg", num_colors=5, output_format="hex")
# With white/black filtering
colors, names, dominance = extract_palette(
"image.jpg",
num_colors=5,
output_format="hex",
ignore_white=True,
ignore_black=True,
white_threshold=240, # optional, default 240
black_threshold=15, # optional, default 15
)
# colors and dominance are parallel lists, sorted by dominance descending
for color, pct in zip(colors, dominance):
print(f"{color} — {pct}%")
# Save to JSON (includes dominance)
save_palette_json(colors, "palette.json", dominance=dominance)
JSON output format
{
"palette": ["#1a2b3c", "#4d5e6f", "..."],
"dominance": [45.2, 30.1, 12.4, 7.8, 4.5]
}
Package Structure
color_palette_extractor/
├── extractor.py
├── palette_image.py
├── utils.py
├── color_naming.py
├── cli.py
└── __init__.py
License
MIT License — Copyright (c) 2026 Youssef Helioui
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file color_palette_extractor-1.2.1.tar.gz.
File metadata
- Download URL: color_palette_extractor-1.2.1.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a4af5cb89c1161a6facb6de3dc1f3658b3d19b453e99e4f341b00685321ce08
|
|
| MD5 |
6d878b7e8f90e782260f900277c8ce96
|
|
| BLAKE2b-256 |
fde21683ba2ad9e66e62e5b3c3977fc925427345bff2f364c7d88fa19678b87c
|
File details
Details for the file color_palette_extractor-1.2.1-py3-none-any.whl.
File metadata
- Download URL: color_palette_extractor-1.2.1-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1af0e73254b8a28510509c0c30bbcb5e71efecd37b18ec216bede32f0e61a417
|
|
| MD5 |
70c871e9707a1acd61a2590bf9e2a2e7
|
|
| BLAKE2b-256 |
317590bc9342dfa02d751bc925c064c22e9a976c9070e0713c3c8cdc54b2d829
|