Craft\Imager_ColorService::getDominantColor PHP 메소드

getDominantColor() 공개 메소드

Get dominant color of image
public getDominantColor ( craft\AssetFileModel | string $image, $quality, $colorValue ) : boolean | string
$image craft\AssetFileModel | string
$quality
$colorValue
리턴 boolean | string
    public function getDominantColor($image, $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)));
        }
        $dominantColor = ColorThief::getColor($pathsModel->sourcePath . $pathsModel->sourceFilename, $quality);
        return $colorValue == 'hex' ? Imager_ColorService::rgb2hex($dominantColor) : $dominantColor;
    }