📜  PHP | imagickdraw line()函数(1)

📅  最后修改于: 2023-12-03 15:03:38.416000             🧑  作者: Mango

PHP | ImagickDraw line() function

The line() function is a part of the ImagickDraw class in PHP. It is used to draw a straight line on the image canvas.

Parameters

The line() function takes four parameters:

  • start x: It specifies the starting x-coordinate of the line.
  • start y: It specifies the starting y-coordinate of the line.
  • end x: It specifies the ending x-coordinate of the line.
  • end y: It specifies the ending y-coordinate of the line.
Syntax
bool ImagickDraw::line ( float $sx , float $sy , float $ex , float $ey )
Return Value

The line() function returns a boolean value. It returns TRUE on success and FALSE on failure.

Example

Below is an example of drawing a line using the ImagickDraw line() function in PHP:

<?php

// Create a new Imagick object
$im = new Imagick();

// Create a new ImagickDraw object
$draw = new ImagickDraw();

// Specify the stroke color as red
$draw->setStrokeColor('red');

// Set the stroke width to 2
$draw->setStrokeWidth(2);

// Draw a line from (10, 10) to (90, 90)
$draw->line(10, 10, 90, 90);

// Draw the image with the ImagickDraw object
$im->drawImage($draw);

// Display the image
header('Content-Type: image/png');
echo $im;

?>
Conclusion

The ImagickDraw line() function is a simple and easy-to-use function for drawing straight lines on the image canvas in PHP. It is useful in various image editing projects where drawing straight lines are required.