The ImagickDraw::pathFinish() function is an inbuilt function in PHP which is used to terminate the current path. This is required when multiple paths are to be drawn in the image.
Syntax:
bool ImagickDraw::pathFinish( void )
Parameters: This function doesn’t accepts any parameter.
Return Value: This function returns TRUE on success.
Exceptions: This function throws ImagickException on error.
Below programs illustrate the ImagickDraw::pathFinish() function in PHP:
Program 1:
<?php // Create a new imagick object $imagick = new Imagick();
// Create a image on imagick object $imagick ->newImage(800, 250, '#1a65f0' );
// Create a new ImagickDraw object $draw = new ImagickDraw();
$draw ->setFillColor( '#2fceeb' );
// Set the stroke color $draw ->setStrokeColor( 'black' );
// Set the stroke width $draw ->setStrokeWidth(15);
// Create a path $draw ->pathStart();
$draw ->pathMoveToAbsolute(50, 50);
$draw ->pathLineToAbsolute(100, 50);
$draw ->pathLineToRelative(0, 50);
$draw ->pathLineToHorizontalRelative(-50);
$draw ->pathFinish();
// Create another path $draw ->pathStart();
$draw ->pathMoveToAbsolute(50, 50);
$draw ->pathMoveToRelative(300, 0);
$draw ->pathLineToRelative(50, 0);
$draw ->pathLineToVerticalRelative(50);
$draw ->pathLineToHorizontalAbsolute(350);
$draw ->pathclose();
$draw ->pathFinish();
// Render the draw commands $imagick ->drawImage( $draw );
// Show the output $imagick ->setImageFormat( 'png' );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?> |
Output:
Program 2:
<?php // Create a new imagick object $imagick = new Imagick();
// Create a image on imagick object $imagick ->newImage(800, 250, '#1a65f0' );
// Create a new ImagickDraw object $draw = new ImagickDraw();
$draw ->setFillColor( 'red' );
// Set the stroke color $draw ->setStrokeColor( 'black' );
// Set the stroke width $draw ->setStrokeWidth(1);
// Create a path $draw ->pathStart();
$draw ->pathMoveToAbsolute(50, 50);
$draw ->pathLineToAbsolute(100, 150);
$draw ->pathLineToRelative(0, 50);
$draw ->pathLineToHorizontalRelative(-50);
$draw ->pathFinish();
$x = 0;
for ( $x ; $x < 10; $x ++) {
// Create another path
$draw ->pathStart();
$draw ->pathMoveToAbsolute(50, 150);
$draw ->pathMoveToRelative( $x * 100, 0);
$draw ->pathLineToRelative(50, 0);
$draw ->pathLineToVerticalRelative(50);
$draw ->pathLineToHorizontalAbsolute(350);
$draw ->pathclose();
$draw ->pathFinish();
} // Render the draw commands $imagick ->drawImage( $draw );
// Show the output $imagick ->setImageFormat( 'png' );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?> |
Output:
Reference: https://www.php.net/manual/en/imagickdraw.pathfinish.php