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

declare(strict_types=1);

namespace 
InterventionImageEncoders;

use 
InterventionImageDriversAbstractEncoder;
use 
InterventionImageExceptionsNotSupportedException;
use 
InterventionImageFormat;
use 
InterventionImageInterfacesEncodedImageInterface;
use 
InterventionImageInterfacesImageInterface;

class 
FormatEncoder extends AbstractEncoder
{
    
/**
     * Encoder options.
     *
     * @var array<int|string, mixed>
     */
    
protected array $options = [];

    
/**
     * Create new encoder instance to encode to given format.
     */
    
public function __construct(protected ?Format $format nullmixed ...$options)
    {
        
$this->options $options;
    }

    
/**
     * {@inheritdoc}
     *
     * @see EncoderInterface::encode()
     *
     * @throws NotSupportedException
     */
    
public function encode(ImageInterface $image): EncodedImageInterface
    
{
        try {
            
$format is_null($this->format) ? $image->origin()->format() : $this->format;
        } catch (
NotSupportedException $e) {
            throw new 
NotSupportedException('Unable to find encoder by unknown origin image format'previous$e);
        }

        return 
$format->encoder(...$this->options)->encode($image);
    }
}
Онлайн: 1
Реклама