Craft\Imager_ColorService::getColorPalette PHP Method

getColorPalette() public method

Gets color palette for image
public getColorPalette ( craft\AssetFileModel | string $image, $colorCount, $quality, $colorValue ) : array
$image craft\AssetFileModel | string
$colorCount
$quality
$colorValue
return array
    public function getColorPalette($image, $colorCount, $quality, $colorValue)
    {
        $pathsModel = new Imager_ImagePathsModel($image);
        if (!IOHelper::getRealPath($pathsModel->sourcePath)) {
            throw new Exception(Craft::t('Source folder “{sourcePath}” does not exist', array('sourcePath' => $pathsModel->sourcePath)));
        }
        if (!IOHelper::fileExists($pathsModel->sourcePath . $pathsModel->sourceFilename)) {
            throw new Exception(Craft::t('Requested image “{fileName}” does not exist in path “{sourcePath}”', array('fileName' => $pathsModel->sourceFilename, 'sourcePath' => $pathsModel->sourcePath)));
        }
        $palette = ColorThief::getPalette($pathsModel->sourcePath . $pathsModel->sourceFilename, $colorCount, $quality);
        return $colorValue == 'hex' ? $this->_paletteToHex($palette) : $palette;
    }