Product10/16/2026·7 min read

Build a Colour Palette From a Photo: Roles, Ratios, Contrast

Build a colour palette from a photo that holds up: choose roles by subject, split 60-30-10, check hue angles and test text against WCAG's 4.5:1.

To build a colour palette from a photo, extract six to eight candidate colours, then assign roles instead of keeping the order the extractor returns: a dominant colour for about 60% of the surface, a secondary for 30% and an accent for 10%. Check that the hues are related, then test every text pairing against the WCAG minimum of 4.5:1. Extraction measures how much of the frame a colour covers. The palette is a decision about what the photo is about, and the method below keeps those two steps apart.

What does a palette extractor actually measure?

Every palette extractor is a colour quantizer. It reduces the tens of thousands of distinct values in a photo to a handful of representatives and reports how many pixels each one stands for. The problem is older than phones: Paul Heckbert's 1982 SIGGRAPH paper on colour image quantization was written for frame buffers with few displayable colours, and showed that many images needing 15 bits per pixel could drop to 8 or fewer with little visible degradation. The median-cut method it is known for is still in common use.

Median cut puts every pixel into one box in RGB space, splits the box across its longest side, and keeps splitting the widest remaining box until there are as many boxes as you asked for. Each box's average becomes a swatch. k-means starts from k guessed centres instead, assigns every pixel to the nearest one, moves each centre to the mean of its pixels and repeats. It is slower and its answer depends on where it started, which gave it a poor reputation for this job until Celebi (2011) showed that an efficient implementation with a good initialisation makes it a very effective colour quantizer.

MethodHow it picks coloursWhat it favoursHow it fails
PopularityCounts binned values and keeps the most frequentLarge flat areasFive near-identical beiges from one wall
Median cutSplits colour space along its longest axis, recursivelyDistinct hues; the same answer every runAverages two-tone lighting into one muddy swatch
k-meansAssigns pixels to the nearest centre, moves centres to the mean, repeatsLow average errorDifferent starting centres, different palette; slower
Saliency-weightedMultiplies each pixel's weight by a predicted-attention map before any of the aboveThe subject over the backdropPicks the wrong one of two subjects

All four rank their output by pixel share. That answers "what covers this photo", which is rarely the question you started with.

Which colour leads, and which only accents?

Give each candidate a role before you judge the palette. The rule of thumb decorators use is 60-30-10: a dominant colour across about 60% of the surface, a secondary across 30%, an accent on the last 10%. On a screen, the 60% is the page background and large panels, the 30% is cards and secondary surfaces, and the 10% is buttons, links and highlights.

A photo's area ranking almost never matches those roles. In a portrait against a wall the wall is the largest cluster; on a beach it is the sand. The colour that made you stop is usually small in the frame, such as a scarf, a door or a flower, and small is the right size for an accent. Take a rust jacket in front of a beige wall with a teal door at the edge: by area the beige comes first and the teal last, but the photo is about the jacket.

  1. Extract six to eight colours, more than you need, so a small accent survives quantization.
  2. Merge near-duplicates. Two swatches that differ only in lightness are usually one surface in light and in shadow.
  3. Choose the lead by subject, not by share: the colour you would name if you described the photo in one word.
  4. Decide where the lead goes. A saturated lead over 60% of a layout is loud, so many palettes give the 60% to a neutral from the same photo and the 30% to the lead.
  5. Keep one accent. A second accent competes with the first.

For the jacket photo that gives beige #D8C3A5 as the ground, rust #B85C38 as the lead and teal #3A7D8C as the accent, with a dark slate #2F4F4F held back for text.

Do the colours belong together?

Harmony is mostly hue angle and lightness spacing, and both can be read off the numbers. Convert each HEX value to HSL and place the hues on the 360° wheel.

  • Analogous: hues within about 30° of each other read as one family. The rust (17°) and the beige (35°) are 18° apart, which is why they sit comfortably together.
  • Complementary: hues about 180° apart pull hardest against each other. The teal (191°) is 174° from the rust, close to a true complement, so it works as a 10% accent and would fight the lead at 30%.
  • Triadic: three hues about 120° apart. It is the hardest of the three to keep calm, and a single scene rarely produces it.

Then check lightness with the hue taken away. Desaturate the palette, or compare relative luminance, and look for two roles that land on the same grey. Rust (0.18) and teal (0.18) do exactly that here: they separate by hue alone, so the accent vanishes in a greyscale print. Darken or lighten one of them until the greys differ.

Will text stay readable on every swatch?

Readable text is the one part of a palette you can test against a standard. WCAG 2.2 success criterion 1.4.3 asks for a contrast ratio of at least 4.5:1 for normal text and 3:1 for large text (18 point, or 14 point bold), and 1.4.11 asks for 3:1 for the visual parts of interface components and graphics. The ratio is (L1 + 0.05) / (L2 + 0.05), where L is relative luminance computed from linearised sRGB channels as 0.2126 R + 0.7152 G + 0.0722 B. It runs from 1:1 to 21:1, and W3C says not to round: 4.48:1 is a fail.

Solving that formula gives a useful constant. Below a relative luminance of about 0.18, white text contrasts more than black; above it, black wins. Many photo palettes sit near that line, because terracottas, sages and dusty blues are mid-tones, and mid-tones are where neither black nor white is comfortable.

SwatchRelative luminanceWhite textBlack textUse it for
Beige #D8C3A50.561.71:112.27:1Background with dark text
Rust #B85C380.184.54:14.63:1Body text passes either way, barely
Terracotta #C05A2E0.194.43:14.74:1Black text only, though white looks right
Sage #8A9A5B0.293.06:16.85:1White only at large sizes
Slate #2F4F4F0.078.93:12.35:1Text colour or a dark ground
Grey #7676760.184.54:14.62:1The lightest neutral grey that passes on white

Two pairings need a check of their own. Rust on beige, the lead on the ground from the same photo, is only 2.65:1, so it fails even for large text; use the rust for fills and the slate (5.22:1 on beige) for words. And a colour that passes as text on white can still fail 1.4.11 as a thin outline or chart line next to a mid-tone neighbour.

Naming and handing off the finished palette

Name colours by role, not by mood: ground #D8C3A5, lead #B85C38, accent #3A7D8C, ink #2F4F4F. A role name stays correct when you swap the hue next season, while "Autumn Ember" does not tell a developer where it goes. For each entry, record the HEX, the role, the intended share and the text colour it passed with.

In code that becomes custom properties (--color-lead: #B85C38;) or design tokens; for a moodboard or a client it becomes an image card. A card that will be printed or viewed on wide-gamut screens raises format questions of its own, covered in saving a colour palette as an image in PNG or P3. The HEX values themselves are readings of light in one photograph rather than of the object, which is why the same jacket gives different HEX codes in different photos. If the palette is headed for your iPhone Home Screen, making aesthetic iPhone Home Screen widgets picks up where this leaves off.

What Tinta automates, and what it leaves to you

Tinta does the extraction step on the iPhone and leaves roles, harmony judgement and contrast to you. Before quantizing, it downsamples the photo and weights every pixel with Apple Vision's attention-based saliency, a heat map of the parts of an image most likely to draw attention, keeping a floor so the background still counts. It then runs median cut and returns six colours ranked by weighted share. The top one becomes the card's main colour band, and tapping another chip swaps it in. The whole pipeline is described in how Tinta reads six colours out of a photo.

Its Harmony Colors option is a different operation from extraction. It starts from a base colour and rotates the hue about 30° either way and 60° beyond, at the same brightness, so it produces an analogous family of generated colours rather than sampled ones; there is no complementary or triadic mode. The mount styles that frame the result are covered in turning a palette into a scheme with Tinta. Tinta is free to use, with an optional Pro subscription billed monthly or yearly.

Two limits matter for this method. The palette is fixed at six sampled chips, and you cannot add a colour of your own or delete one you do not want. And the black-or-white label on each chip flips at a relative luminance of 0.45, not at the 0.18 crossover: that is a caption style, not a contrast check, and the sage above gets white text at about 3:1. Run your own ratios before the palette goes into an interface.

When a photo is the wrong place to start

Start from a photo when the photo is the brief: a mood, a material, a place you want the design to feel like. Start somewhere else in these cases.

  • Brand colours already exist. Sample the photo for an accent at most; the brand owns the lead.
  • Accessibility comes first. For an interface, choose text and background pairs that pass 4.5:1 first, then borrow the accent from the photo.
  • The light is mixed or filtered. Warm lamps with window light, night shots and heavy presets shift every swatch, so the palette describes the edit, not the scene.
  • You need the physical colour. Paint, fabric and print need a measured or swatch-matched value, which a photo cannot give.

If none of those apply, keep the order fixed: extract wide, assign roles, check hue and lightness, test every text pair, then name and export.

Frequently asked questions

How many colours should a palette taken from a photo have?
Three to five working colours cover most layouts: a dominant, a secondary and an accent, plus a dark and a light neutral for text and backgrounds. Extract six to eight candidates first so a small accent survives quantization, then merge swatches that differ only in lightness, because those are usually one surface in light and in shadow.
Why does a colour palette generator keep picking the background?
Most generators rank colours by how many pixels each cluster covers, and in a typical photo the largest cluster is a wall, a sky, a table or sand. The extraction is correct; the ranking answers a different question. Re-rank the swatches by what the photo is about, or use a tool that weights pixels toward the subject before clustering.
What is the 60-30-10 colour rule?
It is a decorator's rule of thumb for proportion: a dominant colour covers about 60% of a space, a secondary about 30% and an accent about 10%. In a screen layout that maps to the background and large panels, then cards and secondary surfaces, then buttons, links and highlights. Treat it as a starting ratio, not a standard.
How do I check whether text is readable on a palette colour?
Compute the WCAG contrast ratio, (L1 + 0.05) / (L2 + 0.05), from the relative luminance of the lighter and the darker colour. WCAG 2.2 asks for at least 4.5:1 for normal text and 3:1 for large text, and the result is not rounded, so 4.48:1 fails. A background with relative luminance above roughly 0.18 gives black text more contrast than white.
Is median cut or k-means better for extracting colours from a photo?
Median cut is fast, gives the same answer every run and separates distinct hues well, which suits picking a handful of swatches. k-means usually lowers the average error but is slower and depends on its starting centres; Celebi (2011) found it very effective once well initialised. For a palette, what you do after extraction matters more than which quantizer ran.

Products in this post

Keep reading