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

declare(strict_types=1);

namespace 
InterventionImageModifiers;

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 
InterventionImageDriversSpecializableModifier;
use 
InterventionImageExceptionsNotSupportedException;
use 
InterventionImageInterfacesColorspaceInterface;

class 
ColorspaceModifier extends SpecializableModifier
{
    public function 
__construct(public string|ColorspaceInterface $target)
    {
        
//
    
}

    
/**
     * Build target color space
     *
     * @throws NotSupportedException
     */
    
protected function targetColorspace(): ColorspaceInterface
    
{
        if (
$this->target instanceof ColorspaceInterface) {
            return 
$this->target;
        }

        if (
class_exists($this->target)) {
            
$colorspace = new $this->target();

            if (!
$colorspace instanceof ColorspaceInterface) {
                throw new 
NotSupportedException(
                    
'Target colorspace "' $this->target '" is not supported by driver',
                );
            }

            return 
$colorspace;
        }

        return 
match (strtolower($this->target)) {
            
'rgb''srgb''rgba''srgba' => new Rgb(),
            
'cmyk' => new Cmyk(),
            
'hsl' => new Hsl(),
            
'hsv''hsb' => new Hsv(),
            
'oklab' => new Oklab(),
            
'oklch' => new Oklch(),
            default => throw new 
NotSupportedException(
                
'Colorspace is not supported by driver',
            ),
        };
    }
}
Онлайн: 1
Реклама