ksubileau / color-thief-php

Grabs the dominant color or a representative color palette from an image. Uses PHP and GD, Imagick or Gmagick.
MIT License
633 stars 64 forks source link

Get dominance percentages for the palette? #25

Open SeBsZ opened 8 years ago

SeBsZ commented 8 years ago

Would it be possible to get some sort of dominance percentage for each color returned in the palette, so I can choose the second most dominant color for example?

ksubileau commented 8 years ago

Possible maybe, but I don't really know how I can return these percentages without breaking the current API... Any ideas ?

wilsmex commented 6 years ago

I need this too. a relative percentage between 0 - 100 or 0 - 1 for each color returned. This way one could query for images with at least xx% of a particular color...

realjoshharrison commented 8 months ago

Possible maybe, but I don't really know how I can return these percentages without breaking the current API... Any ideas ?

How about a new option for $outputFormat such as 'detailed'?

ColorThief::getColor could then return something like:

[
  'color' => $colorInstance, // ColorThief\Color instance – can get preferred colour format from this
  'percentage' => 0.2, // colour dominance
]

And ColorThief::getPalette would return an array of these arrays..?