JavaScript library that extracts the dominant colour and palette from an image, in the browser and Node.js
open sourceMITfree
Color Thief is a JavaScript library, by Lokesh Dhakar, that extracts the dominant colour and a colour palette from an image in the browser or Node.js with the same API. It returns colours with hex and CSS values, whether each is dark and a readable text colour to put on it, and semantic swatches (Vibrant, Muted, DarkVibrant and others). It has full TypeScript types, a synchronous browser API and an async one for Node.js, runs inside a Web Worker through ImageBitmap or OffscreenCanvas, refines its result in three progressive passes, and can quantize in OKLCH for perceptually even palettes. It installs with npm install colorthief or from a CDN, and is MIT licensed.
Problems it solves
- I want to tint my UI with the main colour of an album cover
- I need to pull a colour palette out of an uploaded image in JavaScript
- I want to pick a readable text colour over an image's dominant colour
Features
- Dominant colour and palette from an image
- Semantic swatches such as Vibrant and Muted
- Readable text colour for each colour
- Browser and Node.js with the same API
- Web Worker support
- Progressive three-pass extraction
- OKLCH quantization
