The ImagickDraw::line() function is an inbuilt function in Imagick library of PHP which is used to draw a line. This function draw the line using the current stroke color, stroke opacity, and stroke width.
Syntax:
bool ImagickDraw::line( $sx, $sy, $ex, $ey )
Parameters: This function accepts four parameters as mentioned above and described below:
- $sx: This parameter takes the value of starting x coordinate.
- $sy: This parameter takes the value of starting y coordinate.
- $ex: This parameter takes the value of ending x coordinate.
- $ey: This parameter takes the value of ending y coordinate.
Return Value: This function returns TRUE on success.
Below program illustrate the ImagickDraw::line() function in PHP:
Program:
php
<?php
$draw = new \ImagickDraw();
$draw ->setFillColor( 'red' );
$draw ->line(10, 30, 180, 200);
$imagick = new \Imagick();
$imagick ->newImage(300, 300, 'white' );
$imagick ->setImageFormat( "png" );
$imagick ->drawImage( $draw );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:

Reference: http://php.net/manual/en/imagickdraw.line.php
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
10 Oct, 2021
Like Article
Save Article