color-thief icon indicating copy to clipboard operation
color-thief copied to clipboard

Percentage of color

Open sasharevzin opened this issue 10 years ago • 8 comments

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

sasharevzin avatar Nov 24 '14 15:11 sasharevzin

+1

fallenartist avatar May 05 '15 15:05 fallenartist

+1

kloneets avatar Jun 03 '15 08:06 kloneets

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.)

Mysterarts avatar Oct 06 '15 22:10 Mysterarts

+1

sedrakpc avatar Jan 12 '17 23:01 sedrakpc

+1

upcesar avatar May 25 '17 00:05 upcesar

+1

fahim0623 avatar Oct 27 '19 06:10 fahim0623

+1

FengXianGuo avatar May 28 '20 13:05 FengXianGuo

+1

aycabayraktar avatar Sep 30 '21 12:09 aycabayraktar