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:
@@ -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);
|
||||
|
||||
|
@@ -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()
|
||||
|
Reference in New Issue
Block a user