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

declare(strict_types=1);

namespace 
InterventionImageDriversImagickModifiers;

use 
Imagick;
use 
ImagickException;
use 
InterventionImageExceptionsModifierException;
use 
InterventionImageExceptionsStateException;
use 
InterventionImageInterfacesImageInterface;
use 
InterventionImageInterfacesSpecializedInterface;
use 
InterventionImageModifiersFillTransparentAreasModifier as GenericFillTransparentAreasModifier;

class 
FillTransparentAreasModifier extends GenericFillTransparentAreasModifier implements SpecializedInterface
{
    
/**
     * @throws ModifierException
     * @throws StateException
     */
    
public function apply(ImageInterface $image): ImageInterface
    
{
        
$backgroundColor $this->backgroundColor($this->driver());

        
// get imagickpixel from background color
        
$pixel $this->driver()
            ->
colorProcessor($image)
            ->
export($backgroundColor);

        
// merge transparent areas with the background color
        
foreach ($image as $frame) {
            try {
                
$frame->native()->setImageBackgroundColor($pixel);
                
$frame->native()->setImageAlphaChannel(Imagick::ALPHACHANNEL_REMOVE);
                
$frame->setNative($frame->native()->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN));
            } catch (
ImagickException $e) {
                throw new 
ModifierException(
                    
'Failed to apply ' self::class . ', unable to set image background color',
                    
previous$e,
                );
            }
        }

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