1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-29 16:50:07 +02:00

added ability to handle already allocated colors

This commit is contained in:
Oliver Vogel
2013-02-03 15:24:16 +01:00
parent 8631f998c9
commit 928055ac99
2 changed files with 20 additions and 2 deletions

View File

@@ -553,7 +553,12 @@ class Image
{ {
$alpha = 0; $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) // parse color array like: array(155, 155, 155)
list($r, $g, $b) = $value; 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); return imagecolorallocatealpha($this->resource, $r, $g, $b, $alpha);

View File

@@ -324,6 +324,15 @@ class ImageTest extends PHPUnit_Framework_Testcase
$this->assertEquals($checkColor['green'], 0); $this->assertEquals($checkColor['green'], 0);
$this->assertEquals($checkColor['blue'], 0); $this->assertEquals($checkColor['blue'], 0);
$this->assertEquals($checkColor['alpha'], 64); $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() public function testBrightnessImage()