Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Commit

Permalink
Merge pull request #2 from stefliekens/identify-multipages
Browse files Browse the repository at this point in the history
Make sure to select the first image when parsing multi-paged images
  • Loading branch information
veewee committed Jan 25, 2016
2 parents 7493ec7 + 6b25300 commit de77909
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 4 additions & 3 deletions spec/Phpro/Filesystem/Metadata/Image/IdentifySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
14 changes: 14 additions & 0 deletions src/Phpro/Filesystem/Metadata/Image/Identify.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit de77909

Please sign in to comment.