Python CLI tool for color palette analysis. Extract colors from images and SVG files, generate professional PDF swatches with HEX/RGB/CMYK values, frequency stats, pie charts, color harmonies, and WCAG accessibility ratings.
Project description
ChromaSpec
A Python tool for color palette analysis that extracts colors from SVG or image files (PNG, JPG, etc.) and generates a professional PDF color swatch document with designer-friendly visualizations organized by Red, Green, and Blue sections.
Features
Color Extraction
- Extracts colors from SVG files (via regex) and image files (via pixel analysis)
- Organizes colors into Red, Green, and Blue sections
- Displays HEX, RGB, and CMYK color values
- Shows frequency percentage for each color
- Supports both 3-digit (
#ABC) and 6-digit (#AABBCC) HEX formats - Supports multiple image formats: PNG, JPG, JPEG, GIF, BMP, TIFF, WebP
Designer Visualizations
- Color Distribution - Pie chart and bar chart showing RGB breakdown
- Top Colors & Harmonies - Shows the 5 most used colors with:
- HSL (Hue, Saturation, Lightness) values
- Complementary color (opposite on color wheel)
- Analogous colors (adjacent ±30° on color wheel)
- Accessibility & Contrast - WCAG 2.1 compliance checker:
- Contrast ratios against white and black backgrounds
- AAA/AA/AA Large/Fail ratings
- Recommendations for dark or light backgrounds
PDF Features
- Cover page with image preview and color summary
- Headers and footers on all pages with page numbers
- Colors sorted by frequency (most common first)
- Clean monospaced Courier font for consistent alignment
- Command-line interface with flexible options
Installation
- Clone the repository:
git clone https://github.com/MichailSemoglou/chromaspec.git
cd chromaspec
- Create a virtual environment (recommended):
python3 -m venv venv
source venv/bin/activate # On macOS/Linux
# or
venv\Scripts\activate # On Windows
- Install dependencies:
pip install -r requirements.txt
Usage
Basic Usage
# From SVG file
python chromaspec.py input.svg
# From image file
python chromaspec.py photo.png
python chromaspec.py image.jpg
This will create <input_name>_colors.pdf in the same directory.
Custom Output Path
python chromaspec.py input.png custom_output.pdf
Help
python chromaspec.py --help
Supported Formats
| Format | Extension |
|---|---|
| SVG | .svg |
| PNG | .png |
| JPEG | .jpg, .jpeg |
| GIF | .gif |
| BMP | .bmp |
| TIFF | .tiff |
| WebP | .webp |
Example Output
The generated PDF contains:
-
Cover page with:
- Title and input filename
- Image preview (for image files)
- Color summary (count of Red, Green, Blue colors)
-
Color Distribution page with:
- Pie chart showing RGB distribution
- Bar chart comparing color counts
- Percentage breakdown
-
Top Colors & Harmonies page with:
- The 5 most frequently used colors
- HSL values for each color
- Complementary and analogous color suggestions
-
Accessibility & Contrast page with:
- WCAG contrast ratios vs white and black
- AAA/AA/Fail ratings for each color
- Background usage recommendations
-
Color swatch pages with:
- Section headers for Red, Green, and Blue
- Color rectangles with no borders
- Full color information:
#FF8040 RGB(255,128, 64) CMYK( 0, 50, 75, 0) 0.153%
- Headers and footers on all pages
Requirements
- Python 3.8+
- reportlab >= 4.0.0
- Pillow >= 10.0.0 (for image file support)
How It Works
- Extract:
- For SVG files: Parses and finds all HEX color codes using regex
- For images: Analyzes pixel data to extract dominant colors with frequencies
- Categorize: Groups colors into Red, Green, and Blue based on dominant RGB component
- Convert: Calculates RGB and CMYK values for each color
- Generate: Creates a professional PDF document with cover page and organized color swatch sections
Color Classification
A color is classified based on its dominant RGB component:
- Red: Red component > Green and Blue
- Green: Green component > Red and Blue
- Blue: Blue component > Red and Green
License
MIT License - see LICENSE for details.
Citation
If you use ChromaSpec in your research, please cite it:
@software{semoglou_chromaspec_2025,
author = {Semoglou, Michail},
title = {ChromaSpec: Color Palette Analyzer},
year = {2025},
publisher = {Zenodo},
doi = {10.5281/zenodo.17864788},
url = {https://doi.org/10.5281/zenodo.17864788}
}
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
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 chromaspec-1.0.0.tar.gz.
File metadata
- Download URL: chromaspec-1.0.0.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff124ad8d6ec7fc30284c3711ae2b15ebe7435392538db498281cfc25feebb95
|
|
| MD5 |
9c7f38d10170a769b70f96bb37b435a8
|
|
| BLAKE2b-256 |
9707f472dcc836b55b43b6e08f1413846e31b90713495fc92489c643d43f5ded
|
File details
Details for the file chromaspec-1.0.0-py3-none-any.whl.
File metadata
- Download URL: chromaspec-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
faaa3487da55ca1863126855d67075bbdeab0b15f83835a5bb7c963d8dd12989
|
|
| MD5 |
539cc6b12877044035315593c6e88196
|
|
| BLAKE2b-256 |
e5861ada4866c91ef372604a7a74d4608f1930c9ff8939cfce89f0efee125d71
|