Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including img-to-palette with all npm packages installed. Try it out:

var imgToPalette = require("img-to-palette")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

img-to-palette v1.0.1

Given an image, extracts the color palette.


Given an image, extracts the color palette using the median-cut algorithm.

Screenshot: Viktor's Juric taken from unsplash



Takes as an argument an image object <img> and returns an array of 8 RGB colors in the form of [[r, g, b], [r, g, b] .....]


let imgToPalette = require('img-to-palette')

let rgbArray = imgToPalette(image)
console.log(rgbArray)  // [[14, 7, 27], [34, 17, 31] ....]
console.log(rgbArray.length)  // 8 



RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free