diff --git a/inc/Service/Media/FallbackMediaHandler.php b/inc/Service/Media/FallbackMediaHandler.php index 9003dae7..66203f01 100644 --- a/inc/Service/Media/FallbackMediaHandler.php +++ b/inc/Service/Media/FallbackMediaHandler.php @@ -12,12 +12,27 @@ class FallbackMediaHandler implements MediaHandler { private string $mime; - public function __construct(ImageMetadataReader $image_metadate_reader, string $default_thumb_path) { - $res = $image_metadate_reader->getMetadata($default_thumb_path); + private static function getShape(string $file_path) { + $ret = \getimagesize($file_path); + 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"); + } + + $width = $ret[0]; + $height = $ret[1]; + $mime = $ret['mime']; + return [ $width, $height, $mime ]; + } + + public function __construct(string $default_thumb_path) { + list($width, $height, $mime) = self::getShape($default_thumb_path); $this->path = $default_thumb_path; - $this->width = $res->width; - $this->height = $res->height; - $this->mime = $res->mime; + $this->width = $width; + $this->height = $height; + $this->mime = $mime; } public function supportsMime(string $mime): bool {