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

declare(strict_types=1);

namespace 
InterventionImageDriversImagickModifiers;

use 
Imagick;
use 
InterventionImageExceptionsImageException;
use 
InterventionImageExceptionsModifierException;
use 
InterventionImageInterfacesImageInterface;
use 
InterventionImageInterfacesSpecializedInterface;
use 
InterventionImageModifiersColorizeModifier as GenericColorizeModifier;

class 
ColorizeModifier extends GenericColorizeModifier implements SpecializedInterface
{
    
/**
     * @throws ModifierException
     */
    
public function apply(ImageInterface $image): ImageInterface
    
{
        
$red $this->normalizeLevel($this->red);
        
$green $this->normalizeLevel($this->green);
        
$blue $this->normalizeLevel($this->blue);

        foreach (
$image as $frame) {
            try {
                
$qrange $frame->native()->getQuantumRange();
            } catch (
ImageException $e) {
                throw new 
ModifierException(
                    
'Failed to apply ' self::class . ', unable to get quantum range',
                    
previous$e,
                );
            }

            try {
                
$result $frame->native()->levelImage(0$red$qrange['quantumRangeLong'], Imagick::CHANNEL_RED)
                    && 
$frame->native()->levelImage(0$green$qrange['quantumRangeLong'], Imagick::CHANNEL_GREEN)
                    && 
$frame->native()->levelImage(0$blue$qrange['quantumRangeLong'], Imagick::CHANNEL_BLUE);

                if (
$result === false) {
                    throw new 
ModifierException(
                        
'Failed to apply ' self::class . ', unable to adjust image colors',
                    );
                }
            } catch (
ImageException $e) {
                throw new 
ModifierException(
                    
'Failed to apply ' self::class . ', unable to adjust image colors',
                    
previous$e,
                );
            }
        }

        return 
$image;
    }

    private function 
normalizeLevel(int $level): int
    
{
        return 
$level intval(round($level 5)) : intval(round(($level 100) / 100));
    }
}
Онлайн: 1
Реклама