Fileboy works out the main colours of every image you upload: the dominant colour, up to 16 colours with how much of the image each covers, vibrant and muted swatches, and a text colour that reads well on each. Use them for placeholders while images load, to theme a page around a picture, or to sort and search by colour.
Add the
palette1https://api.fileboy.io/images/get/[:fileboy_id]?transform=palette
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18{ "version": 1, "dominant": { "hex": "#3d5a73", "rgb": [61, 90, 115], "share": 0.4213, "text": "#ffffff", "contrast": 7.22 }, "colors": [ { "hex": "#3d5a73", "rgb": [61, 90, 115], "share": 0.4213, "text": "#ffffff", "contrast": 7.22 }, { "hex": "#e8d9c4", "rgb": [232, 217, 196], "share": 0.2876, "text": "#000000", "contrast": 15.15 }, { "hex": "#c2452d", "rgb": [194, 69, 45], "share": 0.1102, "text": "#ffffff", "contrast": 5.02 } ], "swatches": { "vibrant": { "hex": "#c2452d", ... }, "darkVibrant": null, "lightVibrant": { "hex": "#e8d9c4", ... }, "muted": { "hex": "#3d5a73", ... }, "darkMuted": null, "lightMuted": null }, "transparentShare": 0 }
dominantcolorsshareswatchesvibrantdarkVibrantlightVibrantmuteddarkMutedlightMutedtext#000000#ffffffcontrasttransparentShareThe transform takes these options:
palette:jsonpalette:css~colors:4palette~colors:0~prefix:heropaletteThe palette URL follows the image's own read access: a public image's palette is public, and an image that needs a signed URL needs one for its palette too. Sign the palette URL like any transform URL.
On its own,
paletteformat:json1?transform=crop:100pcx20pc~position:top;palette~colors:3
Whichever of
formatpalettepalette;format:webppalette:css-bg--fg-1<link rel="stylesheet" href="https://api.fileboy.io/images/get/[:fileboy_id]?transform=palette:css~prefix:hero">
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16/* Fileboy colour palette, version 1 */ :root { --hero-dominant: #3d5a73; --hero-dominant-text: #ffffff; --hero-1: #3d5a73; --hero-1-text: #ffffff; --hero-2: #e8d9c4; --hero-2-text: #000000; --hero-vibrant: #c2452d; --hero-vibrant-text: #ffffff; ... } .hero-bg-dominant { background-color: #3d5a73; color: #ffffff; } .hero-fg-dominant { color: #3d5a73; } .hero-bg-1 { background-color: #3d5a73; color: #ffffff; } ...
The management API returns the same palette with your private key, at
GET /files/[:id]/palette?colors=// needs the private key
const palette = await fileboy.getFilePalette(fileId, { colors: 4 })
palette.dominant?.hex // "#2f5d8a"
palette.colors.map(c => [c.hex, c.share]) // most of the image first
palette.swatches.vibrant?.text // "#ffffff" or "#000000", whichever reads betterpalette = fileboy.fetch_file_palette(file_id, colors: 4)
palette["dominant"]["hex"] # "#2f5d8a"
palette["colors"].map { |c| [c["hex"], c["share"]] }palette = client.get_file_palette(file_id, colors=4)
palette["dominant"]["hex"] # "#2f5d8a"
[(c["hex"], c["share"]) for c in palette["colors"]]$palette = $fileboy->getFilePalette($fileId, colors: 4);
echo $palette['dominant']['hex']; // "#2f5d8a"curl "https://api.fileboy.io/files/FILE_ID/palette?colors=4" \
-H "Authorization: token YOUR_SIGNED_TOKEN"File lists from
GET /filesdominantColorShow the dominant colour where the image will be, so the page does not flash white. The React
ImageplaceholderColor1 2 3 4 5// best: the dominantColor you stored or listed on your server, shown at once <Image id={file.id} placeholderColor={file.dominantColor ?? undefined} /> // or let it fetch the palette (a small JSON request) before the image arrives <Image id={file.id} placeholderColor="auto" />
Anywhere else, a background colour on the
img<img src="..." style="background:#3d5a73">versionThe palette is worked out when a JPEG, PNG, WebP, BMP or TIFF image is uploaded and stored with it, so asking for it later does not read the image again. Images uploaded before palettes existed are worked out the first time their palette is asked for, then stored. The dashboard shows it on each image's Metadata tab.
unsupported_imagepalette~colors:20