Файл: vendor/intervention/image/src/Drivers/Gd/Decoders/DataUriImageDecoder.php
Строк: 107
<?php
declare(strict_types=1);
namespace InterventionImageDriversGdDecoders;
use InterventionImageDataUri;
use InterventionImageExceptionsDecoderException;
use InterventionImageExceptionsDriverException;
use InterventionImageExceptionsImageDecoderException;
use InterventionImageExceptionsInvalidArgumentException;
use InterventionImageExceptionsNotSupportedException;
use InterventionImageExceptionsStateException;
use InterventionImageInterfacesDecoderInterface;
use InterventionImageInterfacesImageInterface;
use InterventionImageTraitsCanDetectImageSources;
class DataUriImageDecoder extends BinaryImageDecoder implements DecoderInterface
{
use CanDetectImageSources;
/**
* {@inheritdoc}
*
* @see DecoderInterface::supports()
*/
public function supports(mixed $input): bool
{
return $this->couldBeDataUrl($input);
}
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*
* @throws InvalidArgumentException
* @throws DriverException
* @throws ImageDecoderException
* @throws StateException
* @throws NotSupportedException
*/
public function decode(mixed $input): ImageInterface
{
if ($input instanceof DataUri) {
try {
return parent::decode($input->data());
} catch (DecoderException) {
throw new ImageDecoderException('Data Uri contains unsupported image type');
}
}
if (!is_string($input)) {
throw new InvalidArgumentException(
'Image source must be data uri scheme of type string or ' . DataUri::class,
);
}
try {
return parent::decode(DataUri::parse($input)->data());
} catch (DecoderException) {
throw new ImageDecoderException('Data Uri contains unsupported image type');
}
}
}