---
application: "Intervention Image"
version: "Version 2"
status: "eol"
---

# Image::polygon

## Draw a polygon to the current image



> 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.

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

Define the background-color of the polygon in one of the available [color formats](https://image.intervention.io/v2/getting-started/formats.md).

> 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](https://image.intervention.io/v2/getting-started/formats.md) as second parameter.

### Return Values
Instance of `Intervention\Image\Image`

### Examples

```php
// create empty canvas with background color
$img = Image::canvas(800, 600, '#ddd');

// define polygon points
$points = [
    40,  50,  // Point 1 (x, y)
    20,  240, // Point 2 (x, y)
    60,  60,  // Point 3 (x, y)
    240, 20,  // Point 4 (x, y)
    50,  40,  // Point 5 (x, y)
    10,  10   // Point 6 (x, y)
];

// draw a filled blue polygon with red border
$img->polygon($points, function ($draw) {
    $draw->background('#0000ff');
    $draw->border(1, '#ff0000');
});
```

### See also

- [pixel](https://image.intervention.io/v2/api/pixel.md)
- [line](https://image.intervention.io/v2/api/line.md)
- [rectangle](https://image.intervention.io/v2/api/rectangle.md)
- [circle](https://image.intervention.io/v2/api/circle.md)
- [ellipse](https://image.intervention.io/v2/api/ellipse.md)

---

## Become a Sponsor

### Intervention Image needs your help to keep the project going

Intervention Image is non-commercial, open source licensed and completely free to use. The considerable
effort required to maintain and develop the software is only possible with the financial support
of sponsors. There are two ways in which you can support this project.

- Support via [GitHub Sponsors](https://github.com/sponsors/Intervention)
- Support via [Ko-Fi](https://ko-fi.com/interventionphp)