pixel-color-cruncher
v1.0.1
Published
Given an image, find a palette of colors. Uses a median-cut algorithm
Downloads
4
Maintainers
Readme
#Pixel Color Cruncher
Given an image, gives you the a palette of colors from it. A median-cut color quantization implementation.
Demo
See it in action here: demo!
To use
Pixel cruncher is a WebWorker.
// create web worker
var pixelCruncher = new Worker('/js/pixel-cruncher.js'); // or wherever pixel-cruncher.js is located
pixelCruncher.addEventListener('message', function(e){
var colors = e.data;
// returns an array of [r,g,b] colors that you can now use
doSomethingWith(colors);
});
// spawn worker thread to crunch pixels. num_colors must be multiple of 2
pixelCruncher.postMessage({data: imageData, num_colors: 16});
Refer to js/main.js
for a usage example.
Credits
Shoutout to Giorgio who paired on me with this!