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

declare(strict_types=1);

namespace 
InterventionImage;

use 
InterventionImageDecodersBase64ImageDecoder;
use 
InterventionImageDecodersBinaryImageDecoder;
use 
InterventionImageDecodersDataUriImageDecoder;
use 
InterventionImageDecodersFilePathImageDecoder;
use 
InterventionImageDecodersStreamImageDecoder;
use 
InterventionImageDecodersSplFileInfoImageDecoder;
use 
InterventionImageExceptionsDriverException;
use 
InterventionImageExceptionsImageDecoderException;
use 
InterventionImageExceptionsInvalidArgumentException;
use 
InterventionImageInterfacesAnimationFactoryInterface;
use 
InterventionImageInterfacesDataUriInterface;
use 
InterventionImageInterfacesDecoderInterface;
use 
InterventionImageInterfacesDriverInterface;
use 
InterventionImageInterfacesImageInterface;
use 
InterventionImageInterfacesImageManagerInterface;
use 
InterventionImageTraitsCanResolveDriver;
use 
SplFileInfo;
use 
Stringable;

class 
ImageManager implements ImageManagerInterface
{
    use 
CanResolveDriver;

    public 
DriverInterface $driver;

    
/**
     * Create new image manager instance.
     *
     * @link https://image.intervention.io/v4/basics/configuration-drivers#create-a-new-image-manager-instance
     *
     * @throws InvalidArgumentException
     */
    
public function __construct(string|DriverInterface $drivermixed ...$options)
    {
        
$this->driver $this->resolveDriver($driver, ...$options);
    }

    
/**
     * {@inheritdoc}
     *
     * @see ImageManagerInterface::usingDriver()
     *
     * @throws InvalidArgumentException
     */
    
public static function usingDriver(string|DriverInterface $drivermixed ...$options): ImageManagerInterface
    
{
        return new 
self(self::resolveDriver($driver, ...$options));
    }

    
/**
     * {@inheritdoc}
     *
     * @see ImageManagerInterface::createImage()
     *
     * @throws InvalidArgumentException
     * @throws DriverException
     */
    
public function createImage(
        
int $width,
        
int $height,
        
null|callable|AnimationFactoryInterface $animation null,
    ): 
ImageInterface {
        if (
$animation instanceof AnimationFactoryInterface) {
            return 
$animation->image($this->driver);
        }

        if (
is_callable($animation)) {
            return 
AnimationFactory::build($width$height$animation$this->driver);
        }

        return 
$this->driver->createImage($width$height);
    }

    
/**
     * {@inheritdoc}
     *
     * @see ImageManagerInterface::decode()
     *
     * @throws InvalidArgumentException
     * @throws ImageDecoderException
     * @throws DriverException
     */
    
public function decode(mixed $sourcenull|string|array|DecoderInterface $decoders null): ImageInterface
    
{
        return 
$this->driver->decodeImage(
            
$source,
            
in_array(gettype($decoders), ['string''object']) ? [$decoders] : $decoders,
        );
    }

    
/**
     * {@inheritdoc}
     *
     * @see ImageManagerInterface::decodePath()
     *
     * @throws InvalidArgumentException
     * @throws ImageDecoderException
     * @throws DriverException
     */
    
public function decodePath(string|Stringable $path): ImageInterface
    
{
        return 
$this->decode($pathFilePathImageDecoder::class);
    }

    
/**
     * {@inheritdoc}
     *
     * @see ImageManagerInterface::decodeBinary()
     *
     * @throws InvalidArgumentException
     * @throws ImageDecoderException
     * @throws DriverException
     */
    
public function decodeBinary(string|Stringable $binary): ImageInterface
    
{
        return 
$this->decode($binaryBinaryImageDecoder::class);
    }

    
/**
     * {@inheritdoc}
     *
     * @see ImageManagerInterface::decodeSplFileInfo()
     *
     * @throws InvalidArgumentException
     * @throws ImageDecoderException
     * @throws DriverException
     */
    
public function decodeSplFileInfo(SplFileInfo $splFileInfo): ImageInterface
    
{
        return 
$this->decode($splFileInfoSplFileInfoImageDecoder::class);
    }

    
/**
     * {@inheritdoc}
     *
     * @see ImageManagerInterface::decodeBase64()
     *
     * @throws InvalidArgumentException
     * @throws ImageDecoderException
     * @throws DriverException
     */
    
public function decodeBase64(string|Stringable $base64): ImageInterface
    
{
        return 
$this->decode($base64Base64ImageDecoder::class);
    }

    
/**
     * {@inheritdoc}
     *
     * @see ImageManagerInterface::decodeDataUri()
     *
     * @throws InvalidArgumentException
     * @throws ImageDecoderException
     * @throws DriverException
     */
    
public function decodeDataUri(string|Stringable|DataUriInterface $dataUri): ImageInterface
    
{
        return 
$this->decode($dataUriDataUriImageDecoder::class);
    }

    
/**
     * {@inheritdoc}
     *
     * @see ImageManagerInterface::decodeStream()
     *
     * @throws InvalidArgumentException
     * @throws ImageDecoderException
     * @throws DriverException
     */
    
public function decodeStream(mixed $stream): ImageInterface
    
{
        return 
$this->decode($streamStreamImageDecoder::class);
    }
}
Онлайн: 1
Реклама