diff --git a/inc/Service/Media/DefaultImageFormatReader.php b/inc/Service/Media/DefaultImageFormatReader.php index 7487ecdc..f40a0b7d 100644 --- a/inc/Service/Media/DefaultImageFormatReader.php +++ b/inc/Service/Media/DefaultImageFormatReader.php @@ -2,17 +2,25 @@ namespace Vichan\Service\Media; +/** + * Do not use this if you can. + * + * Some formats may contain no image or may contain multiple images. In these cases, getimagesize() might not be + * able to properly determine the image size. getimagesize() will return zero for width and height in these cases. + * + * getimagesize() is agnostic of any image metadata. + * If e.g. the Exif Orientation flag is set to a value which rotates the image by 90 or 270 degress, index 0 and 1 + * are swapped, i.e. the contain the height and width, respectively. + */ class DefaultImageFormatReader implements ImageFormatReader { - /** - * getimagesize() is agnostic of any image metadata. - * If e.g. the Exif Orientation flag is set to a value which rotates the image by 90 or 270 degress, index 0 and 1 - * are swapped, i.e. the contain the height and width, respectively. - */ public function getSizes(string $file_path): array { - $ret = \getimagesize($file_path); + $ret = \getimagesize($file_path, $info); if ($ret === false) { throw new \RuntimeException("Could not read image sizes of '$file_path'"); } + if ($ret[2] == \IMAGETYPE_UNKNOWN) { + throw new \RuntimeException("Error '$file_path' is not an image"); + } return $ret; } }