forked from leftypol/leftypol
FallbackMediaHandler.php: include size and mime detection
This commit is contained in:
parent
c0e0833053
commit
5fab806aa4
1 changed files with 20 additions and 5 deletions
|
@ -12,12 +12,27 @@ class FallbackMediaHandler implements MediaHandler {
|
||||||
private string $mime;
|
private string $mime;
|
||||||
|
|
||||||
|
|
||||||
public function __construct(ImageMetadataReader $image_metadate_reader, string $default_thumb_path) {
|
private static function getShape(string $file_path) {
|
||||||
$res = $image_metadate_reader->getMetadata($default_thumb_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->path = $default_thumb_path;
|
||||||
$this->width = $res->width;
|
$this->width = $width;
|
||||||
$this->height = $res->height;
|
$this->height = $height;
|
||||||
$this->mime = $res->mime;
|
$this->mime = $mime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function supportsMime(string $mime): bool {
|
public function supportsMime(string $mime): bool {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue