diff --git a/inc/Service/Media/DefaultImageFormatReader.php b/inc/Service/Media/DefaultImageMetadataReader.php similarity index 74% rename from inc/Service/Media/DefaultImageFormatReader.php rename to inc/Service/Media/DefaultImageMetadataReader.php index f40a0b7d..9255e6d5 100644 --- a/inc/Service/Media/DefaultImageFormatReader.php +++ b/inc/Service/Media/DefaultImageMetadataReader.php @@ -1,6 +1,9 @@ prefix = $prefix; - } - - public function getSizes(string $file_path): array { - $arg = escapeshellarg("$file_path[0]"); - $ret_exec = shell_exec_error("{$this->prefix}identify -format \"%w %h\" $arg"); - - if (!\is_string($ret_exec)) { - throw new \RuntimeException("Error while executing identify"); - } - $ret_match = \preg_match('/^(\d+) (\d+)$/', $ret_exec, $m); - if (!$ret_match) { - throw new \RuntimeException("Could not parse identify output"); - } - return [ $m[1], $m[2] ]; - } -} diff --git a/inc/Service/Media/MagickImageMetadataReader.php b/inc/Service/Media/MagickImageMetadataReader.php new file mode 100644 index 00000000..e3f77f4c --- /dev/null +++ b/inc/Service/Media/MagickImageMetadataReader.php @@ -0,0 +1,40 @@ +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"); + + if (!\is_string($ret_exec)) { + throw new \RuntimeException("Error while executing identify"); + } + $ret_match = \preg_match('/^(\d+) (\d+) ([\w\d]+)$/', $ret_exec, $m); + if (!$ret_match) { + throw new \RuntimeException("Could not parse identify output"); + } + + $mime = $this->mime_types->getMimeType($m[3]) ?? 'application/octet-stream'; + return new ImageMetadataResult($m[1], $m[2], $mime); + } +}