From 663892932407ad27afac98b37a4dd0bf0ba33c30 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sat, 24 May 2014 18:56:47 +0200 Subject: [PATCH] allow limitColors to be called with null --- .../Image/Gd/Commands/LimitColorsCommand.php | 2 +- tests/GdSystemTest.php | 10 ++++++++++ tests/ImagickSystemTest.php | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Intervention/Image/Gd/Commands/LimitColorsCommand.php b/src/Intervention/Image/Gd/Commands/LimitColorsCommand.php index dea31b50..a2889bec 100644 --- a/src/Intervention/Image/Gd/Commands/LimitColorsCommand.php +++ b/src/Intervention/Image/Gd/Commands/LimitColorsCommand.php @@ -39,7 +39,7 @@ class LimitColorsCommand extends \Intervention\Image\Commands\AbstractCommand // copy original image imagecopy($resource, $image->getCore(), 0, 0, 0, 0, $size->width, $size->height); - if ($count <= 256) { + if (is_numeric($count) && $count <= 256) { // decrease colors imagetruecolortopalette($resource, true, $count); } diff --git a/tests/GdSystemTest.php b/tests/GdSystemTest.php index 2499a8ee..8ec310f8 100644 --- a/tests/GdSystemTest.php +++ b/tests/GdSystemTest.php @@ -1076,6 +1076,16 @@ class GdSystemTest extends PHPUnit_Framework_TestCase $this->assertColorAtPosition('#e40214', $img, 16, 21); } + public function testLimitColorsNullWithMatte() + { + $img = $this->manager()->make('tests/images/tile.png'); + $img->limitColors(null, '#ff00ff'); + $this->assertColorAtPosition('#b4e000', $img, 0, 0); + $this->assertColorAtPosition('#445160', $img, 8, 8); + $this->assertColorAtPosition('#ff00ff', $img, 0, 8); + $this->assertColorAtPosition('#ff00ff', $img, 15, 0); + } + public function testPickColorFromTrueColor() { $img = $this->manager()->make('tests/images/star.png'); diff --git a/tests/ImagickSystemTest.php b/tests/ImagickSystemTest.php index 8accab48..0ec1db41 100644 --- a/tests/ImagickSystemTest.php +++ b/tests/ImagickSystemTest.php @@ -1049,6 +1049,16 @@ class ImagickSystemTest extends PHPUnit_Framework_TestCase $this->assertColorAtPosition('#e70012', $img, 16, 21); } + public function testLimitColorsNullWithMatte() + { + $img = $this->manager()->make('tests/images/tile.png'); + $img->limitColors(null, '#ff00ff'); + $this->assertColorAtPosition('#b4e000', $img, 0, 0); + $this->assertColorAtPosition('#445160', $img, 8, 8); + $this->assertColorAtPosition('#ff00ff', $img, 0, 8); + $this->assertColorAtPosition('#ff00ff', $img, 15, 0); + } + public function testPickColorFromTrueColor() { $img = $this->manager()->make('tests/images/star.png');