PHP | ImagickDraw pathLineToHorizontalRelative() Function
Last Updated :
30 Dec, 2019
The ImagickDraw::pathLineToHorizontalRelative() function is an inbuilt function in PHP which is used to draw a horizontal line path from the current point to the target point using relative coordinates. The target point then becomes the new current point.
Syntax:
bool ImagickDraw::pathLineToHorizontalRelative( float $x )
Parameters:This function accepts a single parameter $x which holds the x-coordinate.
Return Value: This function returns TRUE on success.
Exceptions: This function throws ImagickException on error.
Below given programs illustrate the ImagickDraw::pathLineToHorizontalRelative() function in PHP:
Program 1:
<?php
$imagick = new Imagick();
$imagick ->newImage(800, 250, 'white' );
$draw = new ImagickDraw();
$draw ->setStrokeColor( 'Green' );
$draw ->setStrokeWidth(5);
$draw ->pathStart();
$draw ->pathMoveToRelative(0, 100);
$draw ->pathLineToHorizontalRelative(1000);
$draw ->pathFinish();
$imagick ->drawImage( $draw );
$imagick ->setImageFormat( 'png' );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:
Program 2:
<?php
$imagick = new Imagick();
$imagick ->newImage(800, 250, 'white' );
$draw = new ImagickDraw();
$color = [ 'blue' , 'red' , 'green' , 'yellow' , 'orange' , 'brown' , 'pink' ];
$draw ->setStrokeWidth(5);
for ( $x = 0; $x < 7; $x ++) {
$draw ->setStrokeColor( $color [ $x ]);
$draw ->pathStart();
$draw ->pathMoveToRelative(0, $x * 40);
$draw ->pathLineToHorizontalRelative(800);
$draw ->pathFinish();
}
$imagick ->drawImage( $draw );
$imagick ->setImageFormat( 'png' );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:
Reference: https://www.php.net/manual/en/imagickdraw.pathlinetohorizontalrelative.php
Share your thoughts in the comments
Please Login to comment...