Файл: vendor/intervention/image/src/Drivers/Imagick/Decoders/FilePathImageDecoder.php
Строк: 94
<?php
declare(strict_types=1);
namespace InterventionImageDriversImagickDecoders;
use Imagick;
use ImagickException;
use InterventionImageExceptionsDirectoryNotFoundException;
use InterventionImageExceptionsDriverException;
use InterventionImageExceptionsFileNotFoundException;
use InterventionImageExceptionsFileNotReadableException;
use InterventionImageExceptionsImageDecoderException;
use InterventionImageExceptionsInvalidArgumentException;
use InterventionImageExceptionsStateException;
use InterventionImageInterfacesImageInterface;
use InterventionImageTraitsCanDetectImageSources;
class FilePathImageDecoder extends NativeObjectDecoder
{
use CanDetectImageSources;
/**
* {@inheritdoc}
*
* @see DecoderInterface::supports()
*/
public function supports(mixed $input): bool
{
return $this->couldBeFilePath($input);
}
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*
* @throws InvalidArgumentException
* @throws DirectoryNotFoundException
* @throws FileNotFoundException
* @throws FileNotReadableException
* @throws DriverException
* @throws StateException
* @throws ImageDecoderException
*/
public function decode(mixed $input): ImageInterface
{
// make sure path is valid
$path = self::readableFilePathOrFail($input);
try {
$imagick = new Imagick();
$imagick->readImage($path);
} catch (ImagickException) {
throw new ImageDecoderException(
'Failed to decode image data from file "' . $path . '"',
);
}
// decode image
$image = parent::decode($imagick);
// set file path on origin
$image->origin()->setFilePath($path);
try {
// extract exif data for the appropriate formats
if (in_array($imagick->getImageFormat(), ['JPEG', 'TIFF', 'TIF'])) {
$image->setExif($this->extractExifData($path));
}
} catch (ImagickException $e) {
throw new ImageDecoderException('Failed to retrieve image format', previous: $e);
}
return $image;
}
}