rectangle — draw a rectangle

Description

public Intervention\Image\Image rectangle(string $color, integer $x1, integer $y1, integer $x2 = 10, integer $y2, [boolean $filled])

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. By default the rectangle will be filled completely, if you want just draw a border pass boolean false as an optional last parameter.

Parameters

color

The color of the rectangle. Pass a color in one of the different color formats.

x1

X-Coordinate of the top-left point of the rectangle.

y1

Y-Coordinate of the top-left point of the rectangle.

x2

X-Coordinate of the bottom-right point of the rectangle.

y2

Y-Coordinate of the bottom-right point of the rectangle.

filled (optional)

Whether to fill the rectangle or not. Default: true

Return Values

Instance of Intervention\Image\Image

Examples

  1. // create empty canvas with background color
  2. $img = Image::canvas(100, 100, '#ddd');
  3. // draw filled blue rectangle
  4. $img->rectangle('#0000ff', 10, 10, 190, 190);
  5. // draw non-filled red rectangle
  6. $img->rectangle('#ff0000', 5, 5, 195, 195, false);
  7. // draw transparent rectangle
  8. $img->rectangle('rgba(255, 255, 255, 0.5)', 5, 5, 195, 195, false);

See also