1.0.1 • Published 9 years ago

pixel-color-cruncher v1.0.1

Weekly downloads
4
License
ISC
Repository
github
Last release
9 years ago

#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!