Browser-based image tool · JPG, PNG, WEBP → hex, RGB, HSL

Colour Palette from Image

Choose a picture and get its main colours, largest share first, with hex, RGB and HSL values. The image is shrunk to 200 px on its long side and its pixels are grouped by code running in this tab.

Image

One JPG, PNG or WEBP, up to 25.00 MB and 50 megapixels.

Drop an image here or click to choose

.jpg, .jpeg, .png, .webp

Palette

Swatches appear here once an image is read

Add an image to see its palette.

Colour Palette from Image

Operator: Abdulla Al Fahad. How tools are built and checked

A brand photo, a product shot or a painting you like usually carries a handful of colours that do most of the work: the large background tone, one or two mid tones, and a small accent that catches the eye. Picking them by hand with an eyedropper tends to land on a single noisy pixel, which is why the hex code from a dropper often looks slightly off once it fills a whole button.

Colour Palette from Image looks at every pixel of a reduced copy of the picture and groups them into 3 to 10 colours, each one the average of the real pixels in its group. The list is sorted by how much of the image each colour covers, and every entry shows that share next to its hex, RGB and HSL values, ready to paste into a stylesheet or a design file.

Key features

  • One JPG, PNG or WEBP image, up to 25 MB and 50 megapixels, checked by its first bytes rather than its name.
  • Palette size from 3 to 10 colours with a slider, default 5; moving it regroups the same 200 px sample without reopening the file.
  • Swatches sorted by share of pixels with the percentage, hex, RGB and HSL for each.
  • A proportional colour bar that shows the shares at a glance.
  • Copy as CSS custom properties or as a JSON array, or copy one hex code at a time.
  • Download a PNG strip with one 200 px block per colour, the share on the block and the hex code underneath.
  • Mostly transparent pixels (alpha under 128) are left out of the count, and the number skipped is shown.

From pixels to swatches and CSS variables

The picture is first drawn onto a canvas no more than 200 px on its long side, so a 4000 × 3000 photo is sampled at 200 × 150, which is 30,000 pixels. Pixels with an alpha value under 128 (out of 255) are skipped, so the transparent surround of a cut-out logo does not show up as a black or white swatch. The image is turned upright according to its EXIF orientation before sampling, though orientation does not change the colours themselves.

The counted pixels go into a histogram of 32 levels per channel that also keeps the exact sum of red, green and blue in each bucket. Median cut then splits the colour space: it repeatedly takes the box with the largest pixel count times colour spread and divides it at the pixel-weighted middle of its widest channel. Six rounds of k-means follow, moving each colour to the average of the pixels closest to it, and a last pass counts the shares. Two results that round to the same hex code are merged into one.

Hex is written in lowercase, RGB as whole numbers from 0 to 255, and HSL with hue in degrees and saturation and lightness in whole percent. The CSS export is a :root block of custom properties named --color-1, --color-2 and so on in share order, and the JSON export is a plain array of hex strings.

How it works

The tool never works on the full-size picture. It decodes the file once, draws it onto a canvas no more than 200 px on its long side, reads the red, green, blue and alpha values of that small copy, and throws the large decoded image away. Everything after that, from the histogram to the swatch list, runs on those 40,000 or fewer pixels.

Grouping uses median cut followed by a short k-means refinement, as described above. Because the reduced pixels are kept in memory, moving the colour slider only reruns the grouping, not the decoding. The PNG strip is drawn on a separate canvas when you press Download.

Common use cases

  • A freelance designer pulls the navy, cream and rust from a client's shopfront photo to start a website theme that matches the physical sign.
  • A presenter takes the five main colours of a conference banner so the chart colours in their slides do not clash with the stage backdrop.
  • A front-end developer pastes the CSS block from a hero illustration straight into a stylesheet and wires the variables to buttons and links.
  • A quilter photographs a stack of fabric and checks what share each colour takes before buying more of the dominant one.

How to use this tool

  1. Pick the picture whose colours you want, ideally cropped to the area that matters, and add it to the Image panel.
  2. Check the preview and the line underneath it for the original and sampled sizes.
  3. Move the Number of colours slider until the swatches stop doubling up or start missing a colour you can see.
  4. Read the share, hex, RGB and HSL on each row.
  5. Press Copy CSS or Copy JSON, or select the text in the boxes below the list.
  6. Press Download PNG for a strip of the swatches to drop into a mood board or a brief.

Example

A 200 × 150 test image: 60% #1e3a5f navy, 30% #f4f1ea cream, 10% #e4572e rust; 5 colours requested

18,000 navy pixels
9,000 cream pixels
3,000 rust pixels

Three swatches (the image holds only three colours, so the tool says so) and the CSS export

1. #1e3a5f  60.0%  rgb(30, 58, 95)    hsl(214, 52%, 25%)
2. #f4f1ea  30.0%  rgb(244, 241, 234) hsl(42, 31%, 94%)
3. #e4572e  10.0%  rgb(228, 87, 46)   hsl(14, 77%, 54%)

:root {
  --color-1: #1e3a5f;
  --color-2: #f4f1ea;
  --color-3: #e4572e;
}

Tips for best results

  • Crop the picture to the part you care about before adding it. A product photo on a white table will otherwise spend one of its swatches, often the largest, on the table.
  • Start with five colours and move the slider up or down while watching the share column. The palette updates straight away because the pixels are already sampled.
  • Use the share figure to decide roles: the colour with the biggest share usually works as a background, and one under 10 percent is often the accent worth keeping for buttons or highlights.
  • For a logo with a transparent background, export it as PNG with the transparency intact. The transparent area is ignored, so the swatches describe only the mark itself.
  • Copy a single hex value with the Copy button on its row when you only need one colour for a quick match.

Common pitfalls

Asking for more colours than the picture really has splits a large area into near-twins, such as two blues a few steps apart, instead of finding a new hue. If two swatches look the same, lower the count.

Because sampling happens at 200 px, a detail that covers only a few dozen pixels in the original, such as a thin red line or a small logo in a corner, can vanish into a neighbouring colour. Crop closer to the detail if you need it.

The swatches are averages, so a photo with soft gradients gives colours that may not appear as any single pixel. That is usually what you want for a theme, but it is not an exact eyedropper reading.

Shares are measured on visible area, not on how important a colour feels. A bright accent on a small object will always rank below a plain wall behind it.

Colours are read as the browser decodes them, in sRGB. A photo saved with a wide-gamut profile may have its most saturated tones clipped on the way in, so the hex codes can be a little duller than what a colour-managed editor shows.

Common errors and how to fix them

A screenshot of a palette from another app gives an extra swatch for the window chrome.
The grey or white frame around the colours is counted like any other pixels and can take a large share. Crop the screenshot to the colour blocks only, then add it again.
The message says the image is over 50 megapixels.
Very large scans and panoramas are refused before decoding so the tab does not run out of memory. Resize the image to under 50 million pixels; for a palette, even 2000 px wide is far more than enough.
Fewer swatches appear than the number on the slider.
The picture holds fewer clearly different colours than you asked for, for example a flat two-colour logo. The notice above the list says how many were found; nothing is missing.
The clipboard buttons say access was blocked.
Some browsers only allow clipboard writes on a secure page with focus. Select the text in the CSS or JSON box and copy it with the keyboard instead.

Best practices

  • Check the palette against the WCAG contrast ratio before using a pair for text; colours taken from a photo are rarely chosen with readability in mind.
  • Keep the exported variable names generic (--color-1) in the stylesheet and map them to roles such as --surface or --accent in one place, so a new palette can be dropped in later.
  • Take palettes from the final, edited version of a photo, not the raw camera file, so the colours match what people will actually see.
  • Save the PNG strip next to the source image in the project folder; it records which picture the colours came from.

Why the largest swatch is often not the colour you noticed

People remember the saturated parts of an image: the red umbrella, the yellow taxi. The share column measures something different, the area each colour covers. On a street photo the grey road and the sky can easily outrank the umbrella several times over, simply because they fill more of the frame.

That is useful rather than wrong. A layout built from a photo usually needs the large neutral tones for backgrounds and the small saturated one for a call to action, and the share tells you which is which. If you want the accent to rank higher, crop around it before sampling.

Choosing between 3 and 10 colours

Three colours suit a minimal theme or a two-tone logo. Five covers most photos: a background, a couple of mid tones and an accent. Going up to eight or ten is useful for illustrations with many flat areas, but on a photo it mostly adds lighter and darker versions of colours that are already there.

A quick test is to look at the colour bar above the list. If two neighbouring segments are hard to tell apart, the count is one too high.

Frequently asked questions

Why does the tool shrink the image before reading colours?

A 200 px copy holds at most 40,000 pixels, few enough to regroup every time the slider moves, and large areas of colour survive the reduction with their average intact. The cost is that very small details can be absorbed into a neighbouring colour.

Are transparent areas counted?

No. Any pixel with an alpha value under 128 is skipped, and the line under the preview says how many were left out. Semi-transparent edges above that value are counted with their stored colour.

Will I get the same palette every time for the same image?

Yes. Median cut and the k-means rounds that follow have no random starting point, so the same file and the same colour count give the same swatches and shares.

Can I get the colours in a format other than hex?

Each row shows RGB and HSL as well as hex. The CSS and JSON exports use hex because it is the form most stylesheets and design tools accept, but you can copy the RGB or HSL text from the row.