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

declare(strict_types=1);

namespace 
InterventionImageDriversImagickModifiers;

use 
Imagick;
use 
ImagickException;
use 
InterventionImageExceptionsModifierException;
use 
InterventionImageInterfacesImageInterface;
use 
InterventionImageInterfacesSpecializedInterface;
use 
InterventionImageModifiersInvertModifier as GenericInvertModifier;

class 
InvertModifier extends GenericInvertModifier implements SpecializedInterface
{
    
/**
     * @throws ModifierException
     */
    
public function apply(ImageInterface $image): ImageInterface
    
{
        
// Imagick::CHANNEL_DEFAULT includes the alpha channel, so a plain
        // negateImage() call inverts transparency along with color and turns
        // fully transparent pixels opaque. Mask the alpha bit off so the
        // result matches the GD driver, where IMG_FILTER_NEGATE only touches
        // the color channels.
        
$channel Imagick::CHANNEL_ALL & ~Imagick::CHANNEL_ALPHA;

        foreach (
$image as $frame) {
            try {
                
$result $frame->native()->negateImage(false$channel);
                if (
$result === false) {
                    throw new 
ModifierException(
                        
'Failed to apply ' self::class . ', unable to invert image colors',
                    );
                }
            } catch (
ImagickException $e) {
                throw new 
ModifierException(
                    
'Failed to apply ' self::class . ', unable to invert image colors',
                    
previous$e,
                );
            }
        }

        return 
$image;
    }
}
Онлайн: 1
Реклама