HeyDreaming

Free · in your browser · copy codes, no account · free account for PNG

Extract a Color Palette From an Image

Loading the tool…

Drop a photo to find its 4 to 10 dominant colors using median-cut quantization. Copy any HEX code or the whole set as CSS variables with no account; a free account saves a PNG swatch strip. Your image is not uploaded.

How do I generate a color palette from an image?

Drop a JPG, PNG, WebP, AVIF or HEIC file into the box above. The tool immediately extracts 6 dominant HEX colors (and lets you switch the Colors menu anywhere from 4 to 10), ordered from the largest pixel group to the smallest. Copy individual HEX values, copy all of them as `--color-1` through `--color-N` CSS variables, or download `palette.png`.

How it works

01

Add your image

Drag one JPG, PNG, WebP, AVIF or HEIC/HEIF file into the box or click to choose it. A new file replaces the previous one.

02

Choose how many colors

The palette starts at 6 colors. Open the Colors menu to pick any count from 4 to 10 and recalculate immediately.

03

Copy codes or download PNG

Click the copy button beside any HEX swatch, click Copy all as CSS variables, or press Download palette.png to save a swatch strip. Copying needs no account; saving the PNG needs a free HeyDreaming account (Google or email, no credit card).

How median-cut sampling picks the dominant colors

When you load an image, the tool draws it onto a canvas capped at 400 px on the longest side, keeps pixels with at least 50% opacity (alpha 128 or higher), and samples every fourth pixel. It then runs median-cut quantization: the color box with the widest red, green or blue channel range is split in two at its median value until the requested number of groups is reached.

Each group is averaged into a single HEX color and sorted from the most populated group to the least populated. Because the algorithm is deterministic, dropping the same image always returns the exact same palette. If a flat logo or monochrome graphic has fewer distinct colors than the count you selected, the tool lists only the distinct colors found rather than padding the strip with duplicates.

CSS variables, PNG swatch strip and sRGB color

Alongside individual HEX copy buttons, Copy all as CSS variables places `--color-1: #rrggbb;` lines on your clipboard ready to paste into a `:root` block. You can also download `palette.png`, a lossless horizontal strip made of 120×120 px square swatches for each extracted color.

Because sampling runs on a standard 2D browser canvas, wide-gamut photos (such as iPhone Display P3 images) are converted to 8-bit sRGB when decoded, so the extracted HEX codes match how colors render in standard web CSS.

What this tool does not do

It does not let you click individual pixels to sample a tiny spot (use Image Color Picker for exact pixel reading), or invent extra colors when an image contains fewer distinct colors than the number you requested.

See all free tools

Keep exploring

Related free tools

Questions

Color Palette Generator: FAQ

Is my photo uploaded to extract the palette?

No. Decoding, median-cut quantization and PNG generation all run in your browser, so your image stays on your device. The page sends usage events to Google Analytics, such as which tool ran and the color count chosen, but never the image.

Why did I get fewer colors than I selected?

The count (4 to 10) is a maximum. If your image has only two or three distinct colors in the sampled copy, the tool stops splitting and shows only the real colors instead of repeating swatches.

How are transparent areas handled?

Pixels with alpha below 128 (more than half transparent) are ignored so a transparent PNG background does not skew the palette toward black or white. If an image has no opaque pixels at all, the tool reports that there are no colors to take.

What size is the downloaded palette.png file?

Each swatch is a 120×120 px square placed side by side, so a 6-color palette downloads as a 720×120 px lossless PNG. Saving it needs a free account; the HEX codes and CSS variables can be copied without one.

Why didn't a tiny bright detail show up in the palette?

Median-cut averages groups of pixels across a 400 px copy to find the overall dominant tones. To grab the exact HEX code of a small highlight or thin line, open the image in Image Color Picker instead.