mirror of
https://github.com/Intervention/image.git
synced 2025-08-20 12:41:23 +02:00
Implement dedicated reading methods for ImageManager
This commit is contained in:
@@ -143,23 +143,23 @@ abstract class AbstractDecoder implements DecoderInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse and retunr a given file path or throw detailed exception if the path is invalid
|
||||
* Parse and return a given file path or throw detailed exception if the path is invalid
|
||||
*
|
||||
* @throws DecoderException
|
||||
*/
|
||||
protected function parseFilePath(mixed $path): string
|
||||
{
|
||||
if (!is_string($path)) {
|
||||
throw new DecoderException('Unable decode image - path must be of type string.');
|
||||
throw new DecoderException('Path must be of type string.');
|
||||
}
|
||||
|
||||
if ($path === '') {
|
||||
throw new DecoderException('Unable decode image - path must not be an empty string.');
|
||||
throw new DecoderException('Path must not be an empty string.');
|
||||
}
|
||||
|
||||
if (strlen($path) > PHP_MAXPATHLEN) {
|
||||
throw new DecoderException(
|
||||
"Unable decode image - the path is longer than the configured max. value of " . PHP_MAXPATHLEN . ".",
|
||||
"Path is longer than the configured max. value of " . PHP_MAXPATHLEN . ".",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -168,11 +168,11 @@ abstract class AbstractDecoder implements DecoderInterface
|
||||
$basename = pathinfo($path, PATHINFO_BASENAME);
|
||||
|
||||
if (!is_dir($dirname)) {
|
||||
throw new DecoderException("Unable decode image - directory ('" . $dirname . "') does not exist.");
|
||||
throw new DecoderException("Directory ('" . $dirname . "') not found.");
|
||||
}
|
||||
|
||||
if (!@is_file($path)) {
|
||||
throw new DecoderException("Unable decode image - file ('" . $basename . "') does not exist.");
|
||||
throw new DecoderException("File ('" . $basename . "') not found.");
|
||||
}
|
||||
|
||||
return $path;
|
||||
|
@@ -41,7 +41,7 @@ class BinaryImageDecoder extends NativeObjectDecoder implements DecoderInterface
|
||||
$gd = @imagecreatefromstring($input);
|
||||
|
||||
if ($gd === false) {
|
||||
throw new DecoderException('Unsupported image format.');
|
||||
throw new DecoderException('Binary data contains unsupported image type.');
|
||||
}
|
||||
|
||||
// create image instance
|
||||
|
@@ -19,13 +19,13 @@ class DataUriImageDecoder extends BinaryImageDecoder implements DecoderInterface
|
||||
public function decode(mixed $input): ImageInterface|ColorInterface
|
||||
{
|
||||
if (!is_string($input)) {
|
||||
throw new DecoderException('Unable to decode input');
|
||||
throw new DecoderException('Data Uri must be of type string.');
|
||||
}
|
||||
|
||||
$uri = $this->parseDataUri($input);
|
||||
|
||||
if (!$uri->isValid()) {
|
||||
throw new DecoderException('Unable to decode input');
|
||||
throw new DecoderException('Input is no valid Data Uri Scheme.');
|
||||
}
|
||||
|
||||
if ($uri->isBase64Encoded()) {
|
||||
|
@@ -18,7 +18,7 @@ class FilePointerImageDecoder extends BinaryImageDecoder
|
||||
public function decode(mixed $input): ImageInterface|ColorInterface
|
||||
{
|
||||
if (!is_resource($input) || !in_array(get_resource_type($input), ['file', 'stream'])) {
|
||||
throw new DecoderException('Unable to decode input');
|
||||
throw new DecoderException("Input must be a resource of type 'file' or 'stream'.");
|
||||
}
|
||||
|
||||
$contents = '';
|
||||
|
@@ -20,7 +20,7 @@ class SplFileInfoImageDecoder extends FilePathImageDecoder implements DecoderInt
|
||||
public function decode(mixed $input): ImageInterface|ColorInterface
|
||||
{
|
||||
if (!is_a($input, SplFileInfo::class)) {
|
||||
throw new DecoderException('Unable to decode input');
|
||||
throw new DecoderException('Input must be of type ' . SplFileInfo::class . '.');
|
||||
}
|
||||
|
||||
return parent::decode($input->getRealPath());
|
||||
|
@@ -28,7 +28,7 @@ class BinaryImageDecoder extends NativeObjectDecoder
|
||||
$imagick = new Imagick();
|
||||
$imagick->readImageBlob($input);
|
||||
} catch (ImagickException) {
|
||||
throw new DecoderException('Unsupported image format.');
|
||||
throw new DecoderException('Binary data contains unsupported image type.');
|
||||
}
|
||||
|
||||
// decode image
|
||||
|
@@ -18,13 +18,13 @@ class DataUriImageDecoder extends BinaryImageDecoder
|
||||
public function decode(mixed $input): ImageInterface|ColorInterface
|
||||
{
|
||||
if (!is_string($input)) {
|
||||
throw new DecoderException('Unable to decode input');
|
||||
throw new DecoderException('Data Uri must be of type string.');
|
||||
}
|
||||
|
||||
$uri = $this->parseDataUri($input);
|
||||
|
||||
if (!$uri->isValid()) {
|
||||
throw new DecoderException('Unable to decode input');
|
||||
throw new DecoderException('Input is no valid Data Uri Scheme.');
|
||||
}
|
||||
|
||||
if ($uri->isBase64Encoded()) {
|
||||
|
@@ -26,7 +26,7 @@ class FilePathImageDecoder extends NativeObjectDecoder
|
||||
$imagick = new Imagick();
|
||||
$imagick->readImage($path);
|
||||
} catch (ImagickException) {
|
||||
throw new DecoderException('Unsupported image format.');
|
||||
throw new DecoderException('File contains unsupported image format.');
|
||||
}
|
||||
|
||||
// decode image
|
||||
|
@@ -18,7 +18,7 @@ class FilePointerImageDecoder extends BinaryImageDecoder
|
||||
public function decode(mixed $input): ImageInterface|ColorInterface
|
||||
{
|
||||
if (!is_resource($input) || !in_array(get_resource_type($input), ['file', 'stream'])) {
|
||||
throw new DecoderException('Unable to decode input');
|
||||
throw new DecoderException("Input must be a resource of type 'file' or 'stream'.");
|
||||
}
|
||||
|
||||
$contents = '';
|
||||
|
@@ -19,7 +19,7 @@ class SplFileInfoImageDecoder extends FilePathImageDecoder
|
||||
public function decode(mixed $input): ImageInterface|ColorInterface
|
||||
{
|
||||
if (!is_a($input, SplFileInfo::class)) {
|
||||
throw new DecoderException('Unable to decode input');
|
||||
throw new DecoderException('Input must be of type ' . SplFileInfo::class . '.');
|
||||
}
|
||||
|
||||
return parent::decode($input->getRealPath());
|
||||
|
Reference in New Issue
Block a user