Skip to content

Commit 7f347e0

Browse files
committed
Add exception for unsupported files; move check to Image
1 parent 64fff63 commit 7f347e0

4 files changed

Lines changed: 12 additions & 2 deletions

File tree

system/Images/Exceptions/ImageException.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ public static function forMissingImage()
1010
return new static(lang('Images.sourceImageRequired'));
1111
}
1212

13+
public static function forFileNotSupported()
14+
{
15+
return new static(lang('Images.fileNotSupported'));
16+
}
17+
1318
public static function forMissingAngle()
1419
{
1520
return new static(lang('Images.rotationAngleRequired'));

system/Images/Handlers/BaseHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ protected function image(): ?Image
242242
// File::__construct has verified the file exists - make sure it is an image
243243
if (! is_int($this->image->imageType))
244244
{
245-
throw ImageException::forInvalidPath();
245+
throw ImageException::forFileNotSupported();
246246
}
247247

248248
// Note that the image has been verified

system/Images/Image.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ public function getProperties(bool $return = false)
137137
{
138138
$path = $this->getPathname();
139139

140-
$vals = getimagesize($path);
140+
if (! $vals = getimagesize($path))
141+
{
142+
throw ImageException::forFileNotSupported();
143+
}
144+
141145
$types = [
142146
1 => 'gif',
143147
2 => 'jpeg',

system/Language/en/Images.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
'gifNotSupported' => 'GIF images are often not supported due to licensing restrictions. You may have to use JPG or PNG images instead.',
2222
'jpgNotSupported' => 'JPG images are not supported.',
2323
'pngNotSupported' => 'PNG images are not supported.',
24+
'fileNotSupported' => 'The supplied file is not a supported image type.',
2425
'unsupportedImageCreate' => 'Your server does not support the GD function required to process this type of image.',
2526
'jpgOrPngRequired' => 'The image resize protocol specified in your preferences only works with JPEG or PNG image types.',
2627
'rotateUnsupported' => 'Image rotation does not appear to be supported by your server.',

0 commit comments

Comments
 (0)