mirror of
https://github.com/Intervention/image.git
synced 2025-08-23 22:12:51 +02:00
added methods rectangle, line, ellipse and circle
This commit is contained in:
@@ -49,6 +49,12 @@ Add the facade of this package to the `$aliases` array.
|
||||
* Image::pixelate - Pixelate current image
|
||||
* Image::greyscale - Turn current image into a greyscale version
|
||||
* Image::text - Write text in current image
|
||||
* Image::fill - Fill image with given hexadecimal color at position x,y
|
||||
* Image::rectangle - Draw rectangle in current image starting at point 1 and ending at point 2
|
||||
* Image::line - Draw a line in current image starting at point 1 and ending at point 2
|
||||
* Image::ellipse - Draw an ellipse centered at given coordinates
|
||||
* Image::circle - Draw a circle centered at given coordinates
|
||||
* Image::pixel - Set single pixel with given hexadecimal color at position x,y
|
||||
* Image::reset - Reset to original image resource
|
||||
* Image::save - Save image in filesystem
|
||||
|
||||
|
@@ -309,6 +309,72 @@ class Image
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw rectangle in current image starting at point 1 and ending at point 2
|
||||
*
|
||||
* @param string $color
|
||||
* @param integer $x1
|
||||
* @param integer $y1
|
||||
* @param integer $x2
|
||||
* @param integer $y2
|
||||
* @param boolean $filled
|
||||
* @return Image
|
||||
*/
|
||||
public function rectangle($color, $x1 = 0, $y1 = 0, $x2 = 10, $y2 = 10, $filled = true)
|
||||
{
|
||||
$callback = $filled ? 'imagefilledrectangle' : 'imagerectangle';
|
||||
call_user_func($callback, $this->resource, $x1, $y1, $x2, $y2, $this->getColor($color));
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a line in current image starting at point 1 and ending at point 2
|
||||
*
|
||||
* @param string $color
|
||||
* @param integer $x1
|
||||
* @param integer $y1
|
||||
* @param integer $x2
|
||||
* @param integer $y2
|
||||
* @return Image
|
||||
*/
|
||||
public function line($color, $x1 = 0, $y1 = 0, $x2 = 10, $y2 = 10)
|
||||
{
|
||||
imageline($this->resource, $x1, $y1, $x2, $y2, $this->getColor($color));
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw an ellipse centered at given coordinates.
|
||||
*
|
||||
* @param string $color
|
||||
* @param integer $x
|
||||
* @param integer $y
|
||||
* @param integer $width
|
||||
* @param integer $height
|
||||
* @return Image
|
||||
*/
|
||||
public function ellipse($color, $x = 0, $y = 0, $width = 10, $height = 10, $filled = true)
|
||||
{
|
||||
$callback = $filled ? 'imagefilledellipse' : 'imageellipse';
|
||||
call_user_func($callback, $this->resource, $x, $y, $width, $height, $this->getColor($color));
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a circle centered at given coordinates
|
||||
*
|
||||
* @param string $color
|
||||
* @param integer $x
|
||||
* @param integer $y
|
||||
* @param integer $radius
|
||||
* @param boolean $filled
|
||||
* @return Image
|
||||
*/
|
||||
public function circle($color, $x = 0, $y = 0, $radius = 10, $filled = true)
|
||||
{
|
||||
return $this->ellipse($color, $x, $y, $radius, $radius, $filled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write text in current image
|
||||
*
|
||||
|
@@ -143,6 +143,36 @@ class ImageTest extends PHPUnit_Framework_Testcase
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
}
|
||||
|
||||
public function testRectangleImage()
|
||||
{
|
||||
$img = $this->getTestImage();
|
||||
$img = $img->rectangle('cccccc', 10, 10, 100, 100);
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
}
|
||||
|
||||
public function testLineImage()
|
||||
{
|
||||
$img = $this->getTestImage();
|
||||
$img = $img->line('cccccc', 10, 10, 100, 100);
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
}
|
||||
|
||||
public function testEllipseImage()
|
||||
{
|
||||
$img = $this->getTestImage();
|
||||
$img = $img->ellipse('cccccc', 10, 10, 100, 50, false);
|
||||
$img = $img->ellipse('666666', 100, 100, 50, 100, true);
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
}
|
||||
|
||||
public function testCircleImage()
|
||||
{
|
||||
$img = $this->getTestImage();
|
||||
$img = $img->circle('cccccc', 10, 10, 100, false);
|
||||
$img = $img->circle('666666', 100, 100, 50, true);
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
}
|
||||
|
||||
public function testResetImage()
|
||||
{
|
||||
$img = $this->getTestImage();
|
||||
|
Reference in New Issue
Block a user