/**
* Gets color palette for image
*
* @param AssetFileModel|string $image
* @param $colorCount
* @param $quality
* @param $colorValue
* @return array
* @throws Exception
*/
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;
}