FallbackMediaHandler.php: include size and mime detection

This commit is contained in:
Zankaria 2025-03-25 22:19:13 +01:00
parent c0e0833053
commit 5fab806aa4

View file

@ -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 {