From 928055ac997d66b616f2cdbf6de7ead028c5e20b Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sun, 3 Feb 2013 15:24:16 +0100 Subject: [PATCH] added ability to handle already allocated colors --- src/Intervention/Image/Image.php | 13 +++++++++++-- tests/ImageTest.php | 9 +++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Intervention/Image/Image.php b/src/Intervention/Image/Image.php index e695de03..bf525901 100644 --- a/src/Intervention/Image/Image.php +++ b/src/Intervention/Image/Image.php @@ -553,7 +553,12 @@ class Image { $alpha = 0; - if (is_array($value)) { + if (is_int($value)) { + + // color is alread allocated + $allocatedColor = $value; + + } elseif(is_array($value)) { // parse color array like: array(155, 155, 155) list($r, $g, $b) = $value; @@ -593,7 +598,11 @@ class Image } } - if (isset($r) && isset($g) && isset($b)) { + if (isset($allocatedColor)) { + + return $allocatedColor; + + } elseif (isset($r) && isset($g) && isset($b)) { return imagecolorallocatealpha($this->resource, $r, $g, $b, $alpha); diff --git a/tests/ImageTest.php b/tests/ImageTest.php index 1b42f825..243ecbc1 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -324,6 +324,15 @@ class ImageTest extends PHPUnit_Framework_Testcase $this->assertEquals($checkColor['green'], 0); $this->assertEquals($checkColor['blue'], 0); $this->assertEquals($checkColor['alpha'], 64); + + $img = new Image(null, 100, 100); + $color = imagecolorallocatealpha($img->resource, 0, 0, 255, 60); + $img->fill($color); + $checkColor = $img->pickColor(50, 50,'array'); + $this->assertEquals($checkColor['red'], 0); + $this->assertEquals($checkColor['green'], 0); + $this->assertEquals($checkColor['blue'], 255); + $this->assertEquals($checkColor['alpha'], 60); } public function testBrightnessImage()