Файл: vendor/intervention/image/src/Drivers/Imagick/Analyzers/ColorspaceAnalyzer.php
Строк: 101
<?php
declare(strict_types=1);
namespace InterventionImageDriversImagickAnalyzers;
use Error;
use Imagick;
use InterventionImageAnalyzersColorspaceAnalyzer as GenericColorspaceAnalyzer;
use InterventionImageColorsCmykColorspace as Cmyk;
use InterventionImageColorsHslColorspace as Hsl;
use InterventionImageColorsHsvColorspace as Hsv;
use InterventionImageColorsOklabColorspace as Oklab;
use InterventionImageColorsOklchColorspace as Oklch;
use InterventionImageColorsRgbColorspace as Rgb;
use InterventionImageExceptionsAnalyzerException;
use InterventionImageInterfacesImageInterface;
use InterventionImageInterfacesSpecializedInterface;
class ColorspaceAnalyzer extends GenericColorspaceAnalyzer implements SpecializedInterface
{
/**
* @throws AnalyzerException
*/
public function analyze(ImageInterface $image): mixed
{
try {
$colorspace = $image->core()->native()->getImageColorspace();
// OKLAB/OKLCH only exist on recent ImageMagick builds, so the
// constants are resolved through defined()/constant() (mirroring the
// ColorspaceModifier) to avoid referencing them where they are
// undefined. Any unexpected resolution error is normalized below.
return match (true) {
$colorspace === Imagick::COLORSPACE_CMYK => new Cmyk(),
$colorspace === Imagick::COLORSPACE_SRGB,
$colorspace === Imagick::COLORSPACE_RGB => new Rgb(),
$colorspace === Imagick::COLORSPACE_HSL => new Hsl(),
$colorspace === Imagick::COLORSPACE_HSB => new Hsv(),
defined(Imagick::class . '::COLORSPACE_OKLAB')
&& $colorspace === constant(Imagick::class . '::COLORSPACE_OKLAB') => new Oklab(),
defined(Imagick::class . '::COLORSPACE_OKLCH')
&& $colorspace === constant(Imagick::class . '::COLORSPACE_OKLCH') => new Oklch(),
default => throw new AnalyzerException('Failed to analyze unknown colorspace'),
};
} catch (Error $e) {
throw new AnalyzerException('Failed to analyze colorspace', previous: $e);
}
}
}