Skip to content
🛠️ToolsShed

Image Color Palette Extractor

Extract the dominant colors from any image and get their HEX, RGB, and HSL values.

Click or drag an image here

About this tool

An image color palette extractor is a tool that analyzes images to identify and extract their dominant colors. Whether you're a designer working on brand consistency, a developer building interfaces, or anyone seeking to understand the color composition of a photograph, this tool instantly reveals the key colors that define an image's visual character. It outputs colors in multiple formats—HEX, RGB, and HSL—so you can use them immediately in design software, web development, or creative projects.

Simply upload or paste an image into the tool, and it will scan the image to detect the most prominent colors. The extracted colors are displayed with their numerical values in HEX (like #FF5733), RGB (red, green, blue decimal values), and HSL (hue, saturation, lightness percentages). This is useful for matching brand colors to new designs, creating complementary color palettes, extracting swatches from inspiration images, or ensuring your website's color scheme aligns with visual references you're working from.

The tool works entirely in your browser—no image is uploaded to a server, so your photos remain private. The extraction process is based on color frequency analysis, meaning it prioritizes the hues that appear most often in the image. Keep in mind that the number of colors extracted and their prominence depend on the image's content; highly varied images may show different dominant colors than simplified graphics.

Frequently Asked Questions

Code Implementation

# Extract dominant colors using colorthief
# pip install colorthief Pillow

from colorthief import ColorThief
from PIL import Image

def get_palette(image_path: str, num_colors: int = 6, quality: int = 1):
    """
    Extract dominant colors from an image.
    quality: 1=best (slow), 10=fast (less accurate)
    Returns list of (r, g, b) tuples.
    """
    ct = ColorThief(image_path)

    # Most dominant single color
    dominant = ct.get_color(quality=quality)
    print(f"Dominant color: RGB{dominant} -> #{dominant[0]:02X}{dominant[1]:02X}{dominant[2]:02X}")

    # Full palette
    palette = ct.get_palette(color_count=num_colors, quality=quality)
    print("\nPalette:")
    for i, (r, g, b) in enumerate(palette):
        hex_color = f"#{r:02X}{g:02X}{b:02X}"
        print(f"  {i+1}. RGB({r}, {g}, {b}) -> {hex_color}")

    return palette

# Alternative: k-means clustering with scikit-learn
# pip install scikit-learn numpy Pillow
import numpy as np
from sklearn.cluster import KMeans

def kmeans_palette(image_path: str, n_colors: int = 6) -> list:
    img = Image.open(image_path).convert("RGB")
    img = img.resize((150, 150))  # Downsample for speed
    pixels = np.array(img).reshape(-1, 3)

    kmeans = KMeans(n_clusters=n_colors, random_state=42, n_init="auto")
    kmeans.fit(pixels)

    centers = kmeans.cluster_centers_.astype(int)
    counts = np.bincount(kmeans.labels_)
    sorted_colors = centers[np.argsort(-counts)]  # Sort by frequency

    result = []
    for r, g, b in sorted_colors:
        hex_color = f"#{r:02X}{g:02X}{b:02X}"
        result.append({"rgb": (r, g, b), "hex": hex_color})
        print(f"RGB({r}, {g}, {b}) -> {hex_color}")

    return result

palette = get_palette("photo.jpg", num_colors=6)
print("\n--- k-means ---")
kmeans_palette("photo.jpg", n_colors=6)

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.