Файл: vendor/intervention/image/src/Drivers/Imagick/Decoders/StreamImageDecoder.php
Строк: 97
<?php
declare(strict_types=1);
namespace InterventionImageDriversImagickDecoders;
use InterventionImageExceptionsDecoderException;
use InterventionImageExceptionsDriverException;
use InterventionImageExceptionsStreamException;
use InterventionImageExceptionsImageDecoderException;
use InterventionImageExceptionsInvalidArgumentException;
use InterventionImageExceptionsStateException;
use InterventionImageInterfacesImageInterface;
class StreamImageDecoder extends BinaryImageDecoder
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::supports()
*/
public function supports(mixed $input): bool
{
return is_resource($input);
}
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*
* @throws InvalidArgumentException
* @throws StreamException
* @throws DriverException
* @throws StateException
*/
public function decode(mixed $input): ImageInterface
{
if (!is_resource($input) || !in_array(get_resource_type($input), ['file', 'stream'])) {
throw new InvalidArgumentException('Image source must be a resource of type "file" or "stream"');
}
$contents = '';
$rewind = rewind($input);
if ($rewind === false) {
throw new StreamException('Failed to rewind position of stream');
}
while (!feof($input)) {
$chunk = fread($input, 1024);
if ($chunk === false) {
throw new StreamException('Failed to read image from stream');
}
$contents .= $chunk;
}
try {
return parent::decode($contents);
} catch (DecoderException) {
throw new ImageDecoderException(
'Failed to decode image from stream, could be unsupported image format',
);
}
}
}