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

declare(strict_types=1);

namespace 
InterventionImageModifiers;

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

class 
ContainModifier extends SpecializableModifier
{
    public function 
__construct(
        public 
int $width,
        public 
int $height,
        public 
null|string|ColorInterface $background null,
        public 
string|Alignment $alignment Alignment::CENTER,
    ) {
        
//
    
}

    
/**
     * Calculate the crop size of the contain resizing process
     *
     * @throws InvalidArgumentException
     */
    
protected function cropSize(ImageInterface $image): SizeInterface
    
{
        return 
$image->size()
            ->
contain(
                
$this->width,
                
$this->height,
            )
            ->
alignPivotTo(
                
$this->resizeSize($image),
                
$this->alignment,
            );
    }

    
/**
     * Calculate the resize target size of the contain resizing process
     *
     * @throws InvalidArgumentException
     */
    
protected function resizeSize(ImageInterface $image): SizeInterface
    
{
        return new 
Size($this->width$this->height);
    }

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