This Python script extracts a color palette from an image and generates various color harmonies. It’s designed for design students and professionals to analyze and utilize color schemes in their projects.
- Extract dominant colors from any image
- Generate color harmonies (Complementary, Analogous, Triadic, Tetradic, Tints, and Shades)
- Create a PDF report with visual representation of colors and harmonies
- Save color information in a text file for easy reference
-
Clone this repository:
git clone https://github.com/MichailSemoglou/color-palette-extractor.git cd color-palette-extractor
-
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the required dependencies:
pip install -r requirements.txt
-
Download the Inter font files (Inter-Bold.ttf and Inter-Regular.ttf) and place them in the same directory as the script.
Run the script from the command line as follows:
python color_palette_extractor.py path/to/your/image.jpg -n 6
path/to/your/image.jpg
: Path to the input image file-n 6
: Number of colors to extract (optional, default is 6)
The script will generate two output files in the same directory as the script:
-
color_info.txt
: A text file containing detailed color information, including:- HEX, RGB, and CMYK values for each color in the extracted palette
- Color harmony information (Complementary, Analogous, Triadic, Tetradic, Tints, and Shades)
-
color_palette.pdf
: A visual report in PDF format, including:- The original image
- The extracted color palette
- Visual representations of each color harmony
Here are some common issues you might encounter and how to resolve them:
-
ModuleNotFoundError: If you see an error like
ModuleNotFoundError: No module named 'numpy'
, it means the required dependencies are not installed. Make sure you’ve runpip install -r requirements.txt
in your virtual environment. -
FileNotFoundError for font files: If you see an error mentioning
Inter-Bold.ttf
orInter-Regular.ttf
, ensure these font files are in the same directory as the script. You can download them from the Inter font website. -
Permission denied when saving output files: Ensure you have write permissions in the directory where you’re running the script.
-
Image file not found: Double-check the path to your image file. Use the full path if the image is not in the same directory as the script.
-
Unexpected color results: For very large images, try increasing the
max_dimension
value in theextract_color_palette
function for potentially more accurate results, at the cost of increased processing time.
If you encounter any other issues, please open an issue on the GitHub repository with a detailed description of the problem and the steps to reproduce it.
- Complementary: Colors opposite each other on the color wheel, creating a high-contrast effect.
- Analogous: Colors adjacent to each other on the color wheel, creating a harmonious and cohesive look.
- Triadic: Three colors evenly spaced on the color wheel, offering a balanced and vibrant color scheme.
- Tetradic: Four colors arranged into two complementary pairs, providing a rich and varied palette.
- Tints: Lighter variations of a color, created by adding white.
- Shades: Darker variations of a color, created by adding black.
- Python 3.6+
- numpy (1.19.5)
- scikit-learn (0.24.2)
- Pillow (8.2.0)
- reportlab (3.5.67)
For a complete list of dependencies with version information, see requirements.txt
.
-
Brand Identity Development: Analyze existing logos or brand imagery to extract key colors and develop complementary palettes.
-
Web Design: Generate color schemes for websites based on a key visual element or photograph.
-
Interior Design: Extract colors from inspiration images to create cohesive room color schemes.
-
Fashion Design: Analyze fabric patterns or inspiration images to develop coordinated clothing collections.
-
Data Visualization: Create harmonious color palettes for charts, graphs, and infographics.
-
Digital Art: Generate color palettes from reference images for digital illustrations or concept art.
-
Photography: Analyze color composition in photographs and develop presets or filters based on extracted palettes.
-
Print Design: Ensure color consistency across various printed materials by extracting and using a consistent palette.
-
Product Design: Develop color schemes for product lines based on trend images or competitor analysis.
-
Marketing Materials: Create visually cohesive marketing campaigns by extracting colors from key visuals.
This project is licensed under the MIT License – see the LICENSE file for details.