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

# Image::line

## Draw a line to the current image



> public Intervention\Image\Image line(int $x1, int $y1, int $x2, int $y2, [Closure $callback])

Draw a line from **x,y point 1** to **x,y point 2** on current image. Define **color and/or width** of line in an optional Closure callback.

### Parameters

#### x1
X-Coordinate of the starting point.

#### y1
Y-Coordinate of the starting point.

#### x2
X-Coordinate of the end point.

#### y2
Y-Coordinate of the end point.

#### callback
Define appearance of line. See examples below. Use the following methods to pass details.

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

Set color of the line in one of the available [color formats](https://image.intervention.io/v2/getting-started/formats.md). Default: `#000000`

> public Intervention\Image\AbstractShape width(integer $width)

Set the width of the line in pixels. **Option is not available with GD driver** Default: `1`


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

### Examples

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

// draw a blue line
$img->line(10, 10, 100, 10, function ($draw) {
    $draw->color('#0000ff');
});

// draw a red line with 5 pixel width
$img->line(10, 10, 195, 195, function ($draw) {
    $draw->color('#f00');
    $draw->width(5);
});
```

### See also

- [pixel](https://image.intervention.io/v2/api/pixel.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)
- [polygon](https://image.intervention.io/v2/api/polygon.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)