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

declare(strict_types=1);

namespace 
InterventionImageEncoders;

use 
InterventionImageExceptionsInvalidArgumentException;
use 
InterventionImageExceptionsNotSupportedException;
use 
InterventionImageInterfacesImageInterface;
use 
InterventionImageInterfacesEncodedImageInterface;

class 
FilePathEncoder extends FileExtensionEncoder
{
    
/**
     * Create new encoder instance to encode to format of file extension in given path.
     */
    
public function __construct(protected ?string $path nullmixed ...$options)
    {
        
parent::__construct(
            
is_null($path) ? $path pathinfo($pathPATHINFO_EXTENSION),
            ...
$options,
        );
    }

    
/**
     * {@inheritdoc}
     *
     * @see EncoderInterface::encode()
     *
     * @throws InvalidArgumentException
     * @throws NotSupportedException
     */
    
public function encode(ImageInterface $image): EncodedImageInterface
    
{
        
$extension is_null($this->path) ?
            
$image->origin()->fileExtension() :
            
pathinfo($this->pathPATHINFO_EXTENSION);

        if (
$extension === null || $extension === '') {
            throw new 
InvalidArgumentException(
                
'Unable to extract file extension from path "' $this->path '"',
            );
        }

        return 
$image->encode(
            
$this->encoderByFileExtension(
                
$extension,
            ),
        );
    }
}
Онлайн: 1
Реклама