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

Image with single histogram bucket causes invalid VBox->volume #41

Closed mreiden closed 6 years ago

mreiden commented 6 years ago

An image that fits in a single histogram bucket (single color image) causes VBox->volume to be invalid and negative (instead of 1) due to not setting rgbMax in addition to rgbMax. This leaves rgbMax at 0 causing VBox to compute a negative and incorrect volume when calculated as $this->volume = (($this->r2 - $this->r1 + 1) * ($this->g2 - $this->g1 + 1) * ($this->b2 - $this->b1 + 1));

ksubileau commented 6 years ago

Thank you for this ! Just one thing, may i ask you to add a test case for this scenario ?

mreiden commented 6 years ago

Added a test.

ksubileau commented 6 years ago

For my information, did you noticed any impact of this miscalculation on the accuracy of the final color palette ? It looks like it's changing the number of colors returned in the palette for a single color image