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

declare(strict_types=1);

namespace 
InterventionImageModifiers;

use 
InterventionImageAlignment;
use 
InterventionImageDriversSpecializableModifier;
use 
InterventionImageExceptionsInvalidArgumentException;
use 
InterventionImageExceptionsStateException;
use 
InterventionImageInterfacesColorInterface;
use 
InterventionImageInterfacesImageInterface;
use 
InterventionImageInterfacesSizeInterface;
use 
InterventionImageSize;

class 
ResizeCanvasModifier extends SpecializableModifier
{
    
/**
     * Create new modifier object.
     */
    
public function __construct(
        public ?
int $width null,
        public ?
int $height null,
        public 
null|string|ColorInterface $background null,
        public 
string|Alignment $alignment Alignment::CENTER,
    ) {
        
//
    
}

    
/**
     * Build the crop size to be used for the ResizeCanvas process.
     *
     * @throws InvalidArgumentException
     */
    
protected function cropSize(ImageInterface $imagebool $relative false): SizeInterface
    
{
        
$size match ($relative) {
            
true => new Size(
                
is_null($this->width) ? $image->width() : $image->width() + $this->width,
                
is_null($this->height) ? $image->height() : $image->height() + $this->height,
            ),
            default => new 
Size(
                
is_null($this->width) ? $image->width() : $this->width,
                
is_null($this->height) ? $image->height() : $this->height,
            ),
        };

        return 
$size->alignPivotTo($image->size(), $this->alignment);
    }

    
/**
     * Return color to fill the newly created areas after rotation.
     *
     * @throws StateException
     */
    
protected function backgroundColor(): ColorInterface
    
{
        return 
$this->driver()->decodeColor(
            
$this->background ?? $this->driver()->config()->backgroundColor,
        );
    }
}
Онлайн: 1
Реклама