ColorThief\ColorThief::getColor PHP Method

getColor() public static method

Use the median cut algorithm to cluster similar colors.
public static getColor ( mixed $sourceImage, integer $quality = 10, array $area = null ) : array | boolean
$sourceImage mixed Path/URL to the image, GD resource, Imagick instance, or image as binary string
$quality integer 1 is the highest quality. There is a trade-off between quality and speed. The bigger the number, the faster the palette generation but the greater the likelihood that colors will be missed.
$area array
return array | boolean
    public static function getColor($sourceImage, $quality = 10, array $area = null)
    {
        $palette = static::getPalette($sourceImage, 5, $quality, $area);
        return $palette ? $palette[0] : false;
    }

Usage Example

 public function whenMediaHasBeenAdded(MediaHasBeenAdded $event)
 {
     $media = $event->media;
     $dominantColor = ColorThief::getColor($media->getPath());
     $hexColor = (new Rgb(...$dominantColor))->toHex();
     $media->setCustomProperty('dominantColor', $hexColor);
     $media->save();
 }
All Usage Examples Of ColorThief\ColorThief::getColor