From fe101ec6ea3e6b2a1376e584f9541addef9f7b72 Mon Sep 17 00:00:00 2001 From: Stef Liekens Date: Wed, 22 Jul 2015 14:21:51 +0200 Subject: [PATCH] Only open/read the first page when the file is a pdf --- .../Filesystem/Metadata/Image/Identify.php | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Phpro/Filesystem/Metadata/Image/Identify.php b/src/Phpro/Filesystem/Metadata/Image/Identify.php index d7efbd4..f85020e 100644 --- a/src/Phpro/Filesystem/Metadata/Image/Identify.php +++ b/src/Phpro/Filesystem/Metadata/Image/Identify.php @@ -48,7 +48,11 @@ protected function parseIdentify(FileInterface $file, array $options = []) { try { $image = $this->imagick; - $image->readImage($file->getPath()); + + $format = strtolower(pathinfo($file->getPath(), PATHINFO_EXTENSION)); + $source = $this->alterSource($file->getPath(), $format); + + $image->readImage($source); $identifyData = $image->identifyImage(); if (isset($options['extended']) && $options['extended']) { @@ -76,4 +80,22 @@ protected function hasSpotColors(Imagick $image) return count($spotColors) ? true : false; } + + /** + * Makes it possible to change the source of a file based on the format. + * Only read/identify the first page of a PDF file. + * + * @param $source + * @param $format + * + * @return string + */ + protected function alterSource($source, $format) + { + if (strtolower($format) == 'pdf') { + return $source . '[0]'; + } + + return $source; + } }