Image::line

Draw a line to the current image

2.7M Downloads / Month

Open Source MIT License

You are viewing the documentation for Intervention Image 2, this version has reached end of life (EOL). Please consider upgrading to version 3.

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

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

Edit