Image::rectangle
Draw a rectangle to the current image
2.9M Downloads / Month
Open Source MIT License
2.9M Downloads / Month
Open Source MIT License
public Intervention\Image\Image rectangle(int $x1, int $y1, int $x2, int $y2, [Closure $callback])
Draw a colored rectangle on current image with top-left corner on x,y point 1 and bottom-right corner at x,y point 2. Define the overall appearance of the shape by passing a Closure callback as an optional parameter.
x-coordinate of the top-left point of the rectangle.
y-coordinate of the top-left point of the rectangle.
x-coordinate of the bottom-right point of the rectangle.
y-coordinate of the bottom-right point of the rectangle.
Define appearance of rectangle. See examples below. Use the following methods to pass details.
public Intervention\Image\AbstractShape background(string $color)
Define the background-color of the rectangle in one of the available color formats.
public Intervention\Image\AbstractShape border(integer $width, string $color)
Define the border of the rectangle. Set width as pixels in the first and the border-color in one of the available color formats as second parameter.
Instance of Intervention\Image\Image
// create empty canvas with background color
$img = Image::canvas(100, 100, '#ddd');
// draw an empty rectangle border
$img->rectangle(10, 10, 190, 190);
// draw filled red rectangle
$img->rectangle(5, 5, 195, 195, function ($draw) {
$draw->background('#ff0000');
});
// draw transparent rectangle with 2px border
$img->rectangle(5, 5, 195, 195, function ($draw) {
$draw->background('rgba(255, 255, 255, 0.5)');
$draw->border(2, '#000');
});