diff --git a/inc/Service/Media/MagickImageMetadataReader.php b/inc/Service/Media/MagickImageMetadataReader.php index a1bb30a8..9d67bc56 100644 --- a/inc/Service/Media/MagickImageMetadataReader.php +++ b/inc/Service/Media/MagickImageMetadataReader.php @@ -1,41 +1,70 @@ prefix = $prefix; - $this->mime_types = $mime_types; } public function getMetadata(string $file_path): ImageMetadataResult { $arg = \escapeshellarg("$file_path[0]"); - $ret_exec = shell_exec_error("{$this->prefix}identify -format \"%w %h %m\" $arg"); + $ret_exec = shell_exec_error("{$this->prefix} identify -format \"%w %h %m\" $arg"); if (!\is_string($ret_exec)) { throw new \RuntimeException("Error while executing identify"); } - $ret_match = \preg_match('/^(\d+) (\d+) ([\w\d]+)$/', $ret_exec, $m); + $ret_match = \preg_match('/^(\d+) (\d+) ([\w\d]+) ([\w]+)$/', $ret_exec, $m); if (!$ret_match) { throw new \RuntimeException("Could not parse identify output"); } + $width = $m[1]; + $height = $m[2]; + $ext = $m[3]; + $orientation_str = $m[4]; - $mime = $this->mime_types->getMimeType($m[3]) ?? 'application/octet-stream'; - return new ImageMetadataResult($m[1], $m[2], $mime); + $mime = Mime\ext_to_mime($ext) ?? 'application/octet-stream'; + $exif_orientation = self::parseOrientation($orientation_str); + return new ImageMetadataResult($width, $height, $mime, $exif_orientation); } }