PHP | ImagickDraw pathMoveToRelative() Function
Last Updated :
23 Dec, 2019
The ImagickDraw::pathMoveToRelative() function is an inbuilt function in PHP which is used to start a new sub-path at the given coordinate using relative coordinates. The current point then becomes the specified coordinate. This function is used for setting initial coordinates before starting drawing anything.
Syntax:
bool ImagickDraw::pathMoveToRelative( float $x, float $y )
Parameters:This function accepts two parameters as mentioned above and described below:
- $x: It specifies the x-coordinate.
- $y: It specifies the y-coordinate.
Return Value: This function returns TRUE on success.
Exceptions: This function throws ImagickException on error.
Below given programs illustrate the ImagickDraw::pathMoveToRelative() function in PHP:
Program 1:
<?php
$imagick = new Imagick();
$imagick ->newImage(800, 250, 'white' );
$draw = new ImagickDraw();
$draw ->setStrokeWidth(30);
$draw ->pathStart();
$draw ->pathMoveToRelative(400, 100);
$draw ->pathLineToHorizontalAbsolute(500);
$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();
$draw ->setStrokeWidth(30);
$draw ->setFillColor( 'red' );
$draw ->pathStart();
$draw ->pathMoveToRelative(400, 100);
$draw ->pathLineToAbsolute(400, 200);
$draw ->pathLineToAbsolute(300, 200);
$draw ->pathLineToAbsolute(300, 100);
$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.pathmovetorelative.php
Share your thoughts in the comments
Please Login to comment...