Extract colors

Javascript library to extract color palette from images simple, fast and lightweight
support browser and Node.js

Image example
Loading image

Random image from Unsplash

Getting started

Install Extract Colors on your project with NPM

npm install extract-colorsnpm install extract-colors get-pixels

Extract color palette with the followed code

import { extractColors } from 'extract-colors'

const src = 'my-image.jpg'

const path = require('path')
const getPixels = require("get-pixels")
const { extractColors } = require('extract-colors')

const src = path.join(__dirname, './my-image.jpg')

getPixels(src, (err, pixels) => {
  if(!err) {
    const data = [...pixels.data]
    const [width, height] = pixels.shape

    extractColors({ data, width, height })

🚀 Performant

This script use two pass. The first optimize calculation to reduce time. The second sort colors with precise calculations.

🌐 Browser & NodeJs

Core function are similar for NodeJs and browser. Extract Colors expose multiple export: browser, NodeJs and ECMAScript Modules.

Typescript support

Fully coded in Typescript to take advantage of typing.

🪡 Fine-grained control

All the options allow you to precisely parameterize the calculations.


Firefox 29+
Chrome 33+
Edge 12+
Opera 19+
Safari 8+
Webview Android 4.4.3+
Samsung Internet 2.0+
Internet Explorer
Node.js 6.0+