forked from leftypol/leftypol
MimeMapMediaHandler.php: use sniff_image
This commit is contained in:
parent
55d4802ca7
commit
298970698e
1 changed files with 1 additions and 16 deletions
|
@ -13,28 +13,13 @@ class MimeMapMediaHandler implements MediaHandler {
|
||||||
*/
|
*/
|
||||||
private mixed $mime_mapper;
|
private mixed $mime_mapper;
|
||||||
|
|
||||||
private static function getShape(string $file_path) {
|
|
||||||
$ret = \getimagesize($file_path);
|
|
||||||
if ($ret === false) {
|
|
||||||
throw new MediaException("Could not read image sizes of '$file_path'", MediaException::ERR_NO_OPEN);
|
|
||||||
}
|
|
||||||
if ($ret[2] == \IMAGETYPE_UNKNOWN) {
|
|
||||||
throw new \RuntimeException("Error '$file_path' is not an image", MediaException::ERR_BAD_MEDIA_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
$width = $ret[0];
|
|
||||||
$height = $ret[1];
|
|
||||||
$mime = $ret['mime'];
|
|
||||||
return [ $width, $height, $mime ];
|
|
||||||
}
|
|
||||||
|
|
||||||
private function generateThumbImpl(
|
private function generateThumbImpl(
|
||||||
string $source_file_mime,
|
string $source_file_mime,
|
||||||
int $max_width,
|
int $max_width,
|
||||||
int $max_height
|
int $max_height
|
||||||
): ThumbGenerationResult {
|
): ThumbGenerationResult {
|
||||||
$thumb_path = ($this->mime_mapper)($source_file_mime);
|
$thumb_path = ($this->mime_mapper)($source_file_mime);
|
||||||
list($thumb_width, $thumb_height, $thumb_mime) = self::getShape($thumb_path);
|
list($thumb_width, $thumb_height, $thumb_mime) = Metadata\sniff_image($thumb_path);
|
||||||
|
|
||||||
return new ThumbGenerationResult(
|
return new ThumbGenerationResult(
|
||||||
$thumb_path,
|
$thumb_path,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue