line — Draw a line

Description

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.

color

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

Set color of the line in one of the available color formats. Default: #000000

width

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

  1. // create empty canvas with background color
  2. $img = Image::canvas(100, 100, '#ddd');
  3. // draw a blue line
  4. $img->line(10, 10, 100, 10, function ($draw) {
  5. $draw->color('#0000ff');
  6. });
  7. // draw a red line with 5 pixel width
  8. $img->line(10, 10, 195, 195, function ($draw) {
  9. $draw->color('#f00');
  10. $draw->width(5);
  11. });

See also