Derive a palette from a photograph
palette_from_imageExtract a color palette from an image, with coverage percentages, WCAG contrast matrix, and theme tokens for light/dark modes. Works locally on PNG/JPEG.
Instructions
Quantises an image with median cut or k-means and returns a small, considered palette: the colours the subject is actually made of, with how much of the image each one covers.
Returns a full WCAG 2.1 contrast matrix alongside the colours, computed from relative luminance, so an unreadable pair cannot be chosen by accident. Also returns a ready-made token set for both theme states, which can be passed straight to init_site.
Reads PNG and JPEG (.png, .jpg, .jpeg). Everything is done locally; nothing is uploaded.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| count | No | How many colours to extract. Default 6. | |
| image | Yes | Full path to a PNG or JPEG file. | |
| algorithm | No | median-cut (default) splits the colour space at medians, then refines with Lloyd iterations so each colour returned is one the image really contains. k-means seeds with k-means++ instead, and is sometimes better on photographs with soft gradients. | |
| merge_similar | No | Drop colours that are nearly identical to one already found. Default true. | |
| sample_budget | No | How many pixels to sample. Default 20000, which is plenty and keeps this instant. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fix | No | ||
| why | No | ||
| tool | Yes | Which tool produced this. | |
| image | No | ||
| format | No | ||
| status | Yes | pass = checked and clean. fail = checked and found problems. skipped = nothing was measured. error = the tool could not run. | |
| problem | No | ||
| headline | Yes | One sentence verdict, safe to show a non-technical user. | |
| swatches | No | ||
| algorithm | No | ||
| dimensions | No | ||
| error_code | No | Set only when status is "error". | |
| corpus_audit | No | ||
| pixels_sampled | No | ||
| readable_pairs | No | ||
| contrast_matrix | No | ||
| suggested_tokens | No | ||
| banned_hexes_checked | No |