- run
npm install
- As it is a module, you can import
prominent
for getting dominant color from the image oraverage
for getting the average color from the image.
prominent('img.png', { amount: 20}).then(colors => {
// console.log(colors);
for(let color of colors) {
//this is black or white then
if((color[0] <= 100 && color[1] <= 100 && color[2] <= 100) || (color[0] >= 200 && color[1] >= 200 && color[2] >= 200)) {
continue;
}
//this is the first non-black/white color
else {
console.log(color);
break;
}
}
})
It accepts first arguments as the image file and second as the number of colors to be present in the array prominence wise. This is a specific use case function, where I am getting the most dominant color which is not black/white.
- Getting the dominant color to set the background image for the lazy loading screen
- Web page color decision using the dominant color of the logo