A dead simple javascript library for extracting the dominant color(s) from an image.
Usage is simple. Create an image (or grab an image URL), then get its dominant color & palette.
var img = document.getElementById('image');
// or
var img = 'http://example.com/path-to-image.jpg'
RGBaster.colors(img, {
success: function(payload) {
// You now have the payload.
console.log(payload.dominant);
console.log(payload.secondary);
console.log(payload.palette);
}
});
The colors
function takes an optional second parameter, which are its options:
RGBaster.colors(img, {
paletteSize: 30,
exclude: [ 'rgb(255,255,255)' ], // don't count white
success: function(payload){
// do something with payload
}
})
rgbaster.js depends on the following browser functionality:
Check the linked resources above to determine current level of browser support.
Brian Gonzalez |
RGBaster was created to modularize a feature of another plugin I built called adaptive backgrounds. Check it out.
MIT