polygon — Draw a polygon

Description

public Intervention\Image\Image polygon(array $points, [Closure $callback])

Draw a colored polygon with given points. You can define the appearance of the polygon by an optional closure callback.

Parameters

points

Points of the polygon defined by a single-dimensional array alternating x, y points. See examples below.

callback (optional)

Define appearance of polygon. Use the following methods to pass details.

background

public Intervention\Image\AbstractShape background( string $color )

Define the background-color of the polygon in one of the available color formats.

border

public Intervention\Image\AbstractShape border( integer $width, string $color )

Define the border of the polygon. Set width as pixels in the first and the border-color in one of the available color formats as second parameter.

Return Values

Instance of Intervention\Image\Image

Examples

  1. // create empty canvas with background color
  2. $img = Image::canvas(800, 600, '#ddd');
  3. // define polygon points
  4. $points = array(
  5. 40, 50, // Point 1 (x, y)
  6. 20, 240, // Point 2 (x, y)
  7. 60, 60, // Point 3 (x, y)
  8. 240, 20, // Point 4 (x, y)
  9. 50, 40, // Point 5 (x, y)
  10. 10, 10 // Point 6 (x, y)
  11. );
  12. // draw a filled blue polygon with red border
  13. $img->polygon($points, function ($draw) {
  14. $draw->background('#0000ff');
  15. $draw->border(1, '#ff0000');
  16. });

See also