Skip to content

Commit

Permalink
Merge pull request php-imagine#391 from romainneutron/fix-353
Browse files Browse the repository at this point in the history
Fix php-imagine#353: Stripping image with invalid ICC profile fails
  • Loading branch information
romainneutron committed Nov 11, 2014
2 parents 031c68a + 14672ce commit 3fc71be
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/Imagine/Gmagick/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ public function flipVertically()
public function strip()
{
try {
$this->profile($this->palette->profile());
try {
$this->profile($this->palette->profile());
} catch (\Exception $e) {
// here we discard setting the profile as the previous incorporated profile
// is corrupted, let's now strip the image
}
$this->gmagick->stripimage();
} catch (\GmagickException $e) {
throw new RuntimeException('Strip operation failed', $e->getCode(), $e);
Expand Down
7 changes: 6 additions & 1 deletion lib/Imagine/Imagick/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,12 @@ public function flipVertically()
public function strip()
{
try {
$this->profile($this->palette->profile());
try {
$this->profile($this->palette->profile());
} catch (\Exception $e) {
// here we discard setting the profile as the previous incorporated profile
// is corrupted, let's now strip the image
}
$this->imagick->stripImage();
} catch (\ImagickException $e) {
throw new RuntimeException('Strip operation failed', $e->getCode(), $e);
Expand Down
Binary file added tests/Imagine/Fixtures/invalid-icc-profile.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions tests/Imagine/Test/Gd/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public function testChangeColorSpaceAndStripImage()
$this->markTestSkipped('GD driver does not support ICC profiles');
}

public function testStripImageWithInvalidProfile()
{
$this->markTestSkipped('GD driver does not support ICC profiles');
}

public function testStripGBRImageHasGoodColors()
{
$this->markTestSkipped('GD driver does not support ICC profiles');
Expand Down
13 changes: 13 additions & 0 deletions tests/Imagine/Test/Image/AbstractImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,19 @@ public function testChangeColorSpaceAndStripImage()
$this->assertEquals('#0082a2', (string) $color);
}

public function testStripImageWithInvalidProfile()
{
$image = $this
->getImagine()
->open('tests/Imagine/Fixtures/invalid-icc-profile.jpg');

$color = $image->getColorAt(new Point(0, 0));
$image->strip();
$afterColor = $image->getColorAt(new Point(0, 0));

$this->assertEquals((string) $color, (string) $afterColor);
}

public function testGetColorAt()
{
$color = $this
Expand Down

0 comments on commit 3fc71be

Please sign in to comment.