How Color Quantization Works, Conceptually
A typical photo can easily contain tens of thousands of distinct RGB values once you count every subtle gradient and shadow - far too many to treat as a "palette." Color quantization solves this by grouping nearby colors into a smaller number of buckets, then treating each bucket's average color as one palette entry.
This tool draws your image onto a small offscreen canvas (downsampled to keep things fast), reads every sampled pixel's red, green, and blue values with getImageData, and reduces each channel's precision - for example collapsing 256 possible values per channel down to 16 - so that pixels which are visually almost identical land in the same bucket. It then counts how many pixels fall into each bucket, sorts buckets by frequency, and walks down that list picking out colors that are both common and different enough from ones already chosen - which is what keeps the final palette from being six near-duplicate shades of the same dominant color.
HEX vs RGB (and Where You'll Use Each)
| Format | Looks Like | Typically Used In |
|---|---|---|
| HEX | #3B82F6 | CSS, design tools (Figma, Photoshop), web development |
| RGB | rgb(59, 130, 246) | CSS rgb()/rgba(), code that needs individual channel values |
| RGB channels | R: 59, G: 130, B: 246 | Image editors, programmatic color math |
HEX and RGB describe the exact same color - they're just two different notations for the same three numbers. HEX packs red, green, and blue into a six-digit base-16 string (two digits per channel), which is compact and easy to paste into a stylesheet. RGB spells the same three values out in plain base-10 numbers, which is often easier to read or feed into code that manipulates color channels directly.
Practical Uses for an Extracted Palette
Tips for Getting a Better Palette
Crop tightly to the subject you actually care about before uploading - a wide shot with a lot of sky or background will spend several of your palette slots on colors you probably don't want. Well-lit, evenly exposed photos also quantize more cleanly than very dark or heavily compressed images, since compression artifacts and noise can scatter what should be one solid color across many slightly different pixel values.
If your source is a logo or graphic with flat, distinct colors, you'll typically get a very clean palette with little variation between swatches - photographs with gradients, shadows, and reflections naturally produce a softer, more blended result, which is expected and not a bug in the extraction.
Frequently Asked Questions
Only slightly, and it's a deliberate tradeoff. The image is downsampled so its longest side is at most 260px before sampling, which keeps pixel analysis fast even on large photos. Because dominant colors are large regions by definition, they survive downsampling essentially unchanged - an image would need to shrink drastically before a genuinely dominant color started disappearing from the palette.
The algorithm aims for 8 visually distinct colors, but only accepts a candidate into the palette if it's far enough - in color distance - from every color already chosen. That's what prevents a palette of eight near-identical shades of the same blue. A genuinely low-variety image, like a flat logo or a solid-color background, may not have enough distinct colors to pass that test, so the palette naturally comes out shorter, sometimes as few as 6 or fewer.
It's a close approximation, not a pixel-perfect count. The percentage reflects a color's share among the pixels sampled from the downscaled image - not literally every pixel in the original file - and pixels merged into the same bucket count together. Treat it as a reliable guide to which colors are most dominant relative to each other, not a scientific measurement.
An image with many unrelated colors spreads pixels across far more buckets, so the top buckets end up smaller and less dominant than in a simpler image. Cropping to the region you actually care about before uploading usually gives a more focused palette.
Yes. Fully or mostly transparent pixels are excluded from the sample so they don't skew the palette toward whatever background color happens to show through.