mirror of
https://github.com/Intervention/image.git
synced 2025-01-17 20:28:21 +01:00
improved fill method
This commit is contained in:
parent
1bfd80ccac
commit
68352b3ffc
@ -1054,7 +1054,7 @@ class Image
|
||||
* @param integer $pos_y
|
||||
* @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')) {
|
||||
|
||||
@ -1086,8 +1086,14 @@ class Image
|
||||
// fill with color
|
||||
$source = $this->parseColor($source);
|
||||
}
|
||||
|
||||
imagefill($this->resource, $pos_x, $pos_y, $source);
|
||||
|
||||
if (is_int($pos_x) && is_int($pos_y)) {
|
||||
// floodfill if exact position is defined
|
||||
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;
|
||||
}
|
||||
|
@ -1242,6 +1242,20 @@ class ImageTest extends PHPUnit_Framework_Testcase
|
||||
}
|
||||
|
||||
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');
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
@ -1253,6 +1267,22 @@ class ImageTest extends PHPUnit_Framework_Testcase
|
||||
$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()
|
||||
{
|
||||
$img = $this->getTestImage();
|
||||
|
Loading…
x
Reference in New Issue
Block a user