Вход Регистрация
Файл: vendor/intervention/image/src/Drivers/Imagick/Modifiers/ColorspaceModifier.php
Строк: 64
<?php

declare(strict_types=1);

namespace 
InterventionImageDriversImagickModifiers;

use 
Imagick;
use 
InterventionImageExceptionsNotSupportedException;
use 
InterventionImageInterfacesColorspaceInterface;
use 
InterventionImageInterfacesImageInterface;
use 
InterventionImageColorsCmykColorspace as CmykColorspace;
use 
InterventionImageColorsRgbColorspace as RgbColorspace;
use 
InterventionImageInterfacesSpecializedInterface;
use 
InterventionImageModifiersColorspaceModifier as GenericColorspaceModifier;

class 
ColorspaceModifier extends GenericColorspaceModifier implements SpecializedInterface
{
    
/**
     * Map own colorspace classname to Imagick classnames
     *
     * @var array<string, int>
     */
    
protected static array $mapping = [
        
RgbColorspace::class => Imagick::COLORSPACE_SRGB,
        
CmykColorspace::class => Imagick::COLORSPACE_CMYK,
    ];

    public function 
apply(ImageInterface $image): ImageInterface
    
{
        
$colorspace $this->targetColorspace();

        
$imagick $image->core()->native();
        
$imagick->transformImageColorspace(
            
$this->getImagickColorspace($colorspace)
        );

        return 
$image;
    }

    
/**
     * @throws NotSupportedException
     */
    
private function getImagickColorspace(ColorspaceInterface $colorspace): int
    
{
        if (!
array_key_exists($colorspace::class, self::$mapping)) {
            throw new 
NotSupportedException('Given colorspace is not supported.');
        }

        return 
self::$mapping[$colorspace::class];
    }
}
Онлайн: 2
Реклама