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

Can get the color ratio #46

Open songyongshuo opened 5 years ago

songyongshuo commented 5 years ago

Update file CMap.php:28

public function palette() {

$total = array_sum($this->vboxes->map(function ($x) {
    return $x['vbox']->count();
}));

return $this->vboxes->map(function ($vb) use ($total) {
    return array($vb['color'], intval($vb['vbox']->count() / floatval($total) * 100));
});

}