color-thief
color-thief copied to clipboard
Percentage of color
Hello,
Is it possible to know the percentage of picked color? If on output we receive 9 colors so what is the percentage of each of them?
Thanks
+1
+1
Maybe not the best solution, but you can change the function palette line 351 in color-thief.js:
palette: function() {
return this.vboxes.map(function(vb) { return vb.color.concat(vb.vbox._count);});
}
When you will use getColor() or getPalette(), the array of each color will still contains red, green and blue but also at the index 3, the count of pixels of this color (or close). Calculate the percentage should be easy with the size of the picture or the sum of the color counts! (Return an object should be better but this solution avoid to change your code if you already use these functions.)
+1
+1
+1
+1
+1