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

declare(strict_types=1);

namespace 
InterventionImageDriversImagickModifiers;

use 
DivisionByZeroError;
use 
ImagickException;
use 
InterventionImageExceptionsModifierException;
use 
InterventionImageInterfacesFrameInterface;
use 
InterventionImageInterfacesImageInterface;
use 
InterventionImageInterfacesSpecializedInterface;
use 
InterventionImageModifiersPixelateModifier as GenericPixelateModifier;

class 
PixelateModifier extends GenericPixelateModifier implements SpecializedInterface
{
    
/**
     * @throws ModifierException
     */
    
public function apply(ImageInterface $image): ImageInterface
    
{
        foreach (
$image as $frame) {
            
$this->pixelateFrame($frame);
        }

        return 
$image;
    }

    
/**
     * @throws ModifierException
     */
    
protected function pixelateFrame(FrameInterface $frame): void
    
{
        
$size $frame->size();

        try {
            
$result $frame->native()->scaleImage(
                (int) 
round(max(1$size->width() / $this->size)),
                (int) 
round(max(1$size->height() / $this->size)),
            ) && 
$frame->native()->scaleImage(
                
$size->width(),
                
$size->height(),
            );

            if (
$result === false) {
                throw new 
ModifierException(
                    
'Failed to apply ' self::class . ', unable to pixelate image',
                );
            }
        } catch (
ImagickException $e) {
            throw new 
ModifierException(
                
'Failed to apply ' self::class . ', unable to pixelate image',
                
previous$e,
            );
        } catch (
DivisionByZeroError $e) {
            throw new 
ModifierException(
                
'Failed to apply ' self::class . ', unable to pixelate image',
                
previous$e,
            );
        }
    }
}
Онлайн: 1
Реклама