mirror of
https://github.com/Intervention/image.git
synced 2025-08-12 08:54:03 +02:00
improved fill method
This commit is contained in:
@@ -1054,7 +1054,7 @@ class Image
|
|||||||
* @param integer $pos_y
|
* @param integer $pos_y
|
||||||
* @return Image
|
* @return Image
|
||||||
*/
|
*/
|
||||||
public function fill($source, $pos_x = 0, $pos_y = 0)
|
public function fill($source, $pos_x = null, $pos_y = null)
|
||||||
{
|
{
|
||||||
if (is_a($source, 'Intervention\Image\Image')) {
|
if (is_a($source, 'Intervention\Image\Image')) {
|
||||||
|
|
||||||
@@ -1087,7 +1087,13 @@ class Image
|
|||||||
$source = $this->parseColor($source);
|
$source = $this->parseColor($source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_int($pos_x) && is_int($pos_y)) {
|
||||||
|
// floodfill if exact position is defined
|
||||||
imagefill($this->resource, $pos_x, $pos_y, $source);
|
imagefill($this->resource, $pos_x, $pos_y, $source);
|
||||||
|
} else {
|
||||||
|
// fill whole image otherwise
|
||||||
|
imagefilledrectangle($this->resource, 0, 0, $this->width - 1, $this->height - 1, $source);
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@@ -1242,6 +1242,20 @@ class ImageTest extends PHPUnit_Framework_Testcase
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testFillImageWithPath()
|
public function testFillImageWithPath()
|
||||||
|
{
|
||||||
|
$img = Image::canvas(100, 100, '#ffa600')->fill('public/circle.png');
|
||||||
|
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||||
|
$this->assertInternalType('int', $img->width);
|
||||||
|
$this->assertInternalType('int', $img->height);
|
||||||
|
$this->assertEquals($img->width, 100);
|
||||||
|
$this->assertEquals($img->height, 100);
|
||||||
|
$this->assertEquals('#ffa600', $img->pickColor(0, 0, 'hex'));
|
||||||
|
$this->assertEquals('#322000', $img->pickColor(12, 12, 'hex'));
|
||||||
|
$this->assertEquals('#ffa600', $img->pickColor(99, 99, 'hex'));
|
||||||
|
$this->assertEquals('#322000', $img->pickColor(80, 80, 'hex'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFillImageWithTransparentImage()
|
||||||
{
|
{
|
||||||
$img = Image::canvas(32, 32)->fill('public/tile.png');
|
$img = Image::canvas(32, 32)->fill('public/tile.png');
|
||||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||||
@@ -1253,6 +1267,22 @@ class ImageTest extends PHPUnit_Framework_Testcase
|
|||||||
$this->assertEquals('#445160', $img->pickColor(31, 31, 'hex'));
|
$this->assertEquals('#445160', $img->pickColor(31, 31, 'hex'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFillWithPosition()
|
||||||
|
{
|
||||||
|
$img = Image::make('public/tile.png')->fill('#ff00ff', 0, 0);
|
||||||
|
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||||
|
$this->assertEquals('#ff00ff', $img->pickColor(0, 0, 'hex'));
|
||||||
|
$this->assertEquals('#445160', $img->pickColor(15, 15, 'hex'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFillWithoutPosition()
|
||||||
|
{
|
||||||
|
$img = Image::make('public/tile.png')->fill('#ff00ff');
|
||||||
|
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||||
|
$this->assertEquals('#ff00ff', $img->pickColor(0, 0, 'hex'));
|
||||||
|
$this->assertEquals('#ff00ff', $img->pickColor(15, 15, 'hex'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testPixelImage()
|
public function testPixelImage()
|
||||||
{
|
{
|
||||||
$img = $this->getTestImage();
|
$img = $this->getTestImage();
|
||||||
|
Reference in New Issue
Block a user