From 6b25300ca32b9e7220d7b56bb278ff119c79a9d6 Mon Sep 17 00:00:00 2001 From: Stef Liekens Date: Mon, 25 Jan 2016 11:36:43 +0100 Subject: [PATCH] Make sure to select the first image when parsing multi-paged images --- composer.json | 2 +- .../Filesystem/Metadata/Image/IdentifySpec.php | 7 ++++--- src/Phpro/Filesystem/Metadata/Image/Identify.php | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index ac2fee5..05cc04d 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "zendframework/zend-stdLib": "~2.3" }, "require-dev": { - "phpspec/phpspec": "dev-master", + "phpspec/phpspec": "~2.0.1", "fabpot/PHP-CS-Fixer": "*" }, "autoload": { diff --git a/spec/Phpro/Filesystem/Metadata/Image/IdentifySpec.php b/spec/Phpro/Filesystem/Metadata/Image/IdentifySpec.php index 4ab6c77..781448f 100644 --- a/spec/Phpro/Filesystem/Metadata/Image/IdentifySpec.php +++ b/spec/Phpro/Filesystem/Metadata/Image/IdentifySpec.php @@ -22,9 +22,10 @@ public function it_is_initializable() public function it_should_be_able_to_load_metadata(Filesystem $filesystem, \Imagick $imagick) { $file = new LocalFile($this->file); - $imagick->readimage($this->file)->shouldBeCalled(); - $imagick->identifyimage()->willReturn(['key' => 'value']); - $imagick->getimageproperties('*SpotColor*')->willReturn([1]); + $imagick->readImage($this->file)->shouldBeCalled(); + $imagick->getNumberImages()->willReturn(0); + $imagick->identifyImage()->willReturn(['key' => 'value']); + $imagick->getImageProperties('*SpotColor*')->willReturn([1]); $imagick->clear()->shouldBeCalled(); $this->getMetadataForFile($file, ['extended' => true])->shouldReturn([ diff --git a/src/Phpro/Filesystem/Metadata/Image/Identify.php b/src/Phpro/Filesystem/Metadata/Image/Identify.php index f85020e..10c1238 100644 --- a/src/Phpro/Filesystem/Metadata/Image/Identify.php +++ b/src/Phpro/Filesystem/Metadata/Image/Identify.php @@ -53,6 +53,8 @@ protected function parseIdentify(FileInterface $file, array $options = []) $source = $this->alterSource($file->getPath(), $format); $image->readImage($source); + $this->handleMultiPages($image); + $identifyData = $image->identifyImage(); if (isset($options['extended']) && $options['extended']) { @@ -98,4 +100,16 @@ protected function alterSource($source, $format) return $source; } + + /** + * Make sure to select the first image when parsing multi-paged images. + * + * @param Imagick $image + */ + protected function handleMultiPages($image) + { + if ($image->getNumberImages() > 1) { + $image->setIteratorIndex(0); + } + } }