PHP | ImagickDraw pathLineToRelative() Function

The ImagickDraw::pathLineToRelative() function is an inbuilt function in PHP which is used to draw a line path from the current point to the given coordinate using relative coordinates. Then the coordinate becomes the new current point. The initial point can be set using pathMoveToRelative() function.

Syntax:

bool ImagickDraw::pathLineToRelative( float $x, float $y )

Parameters: This function accepts two parameters as mentioned above and described below:

  • $x: It specifies the starting x-coordinate.
  • $y: It specifies the starting y-coordinate.

Return Value: This function returns TRUE on success.

Below programs illustrate the ImagickDraw::pathLineToRelative() function in PHP:



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new imagick object
$imagick = new Imagick();
  
// Create a image on imagick object
$imagick->newImage(800, 250, 'white');
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Set the fill color
$draw->setFillColor('black');
  
// Create a path
$draw->pathStart();
  
// Draw a line
// Start coordinates of line
$draw->pathMoveToRelative(350, 50);
  
// End coordinates of line
$draw->pathLineToRelative(50, 150);
  
// End the path
$draw->pathFinish();
  
// Render the draw commands
$imagick->drawImage($draw);
  
// Show the output
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

chevron_right


Output:

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new imagick object
$imagick = new Imagick();
  
// Create a image on imagick object
$imagick->newImage(800, 250, 'white');
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Set the fill color
$draw->setFillColor('yellow');
  
// Set the stroke color
$draw->setStrokeColor('black');
  
// Set the stroke width
$draw->setStrokeWidth(1);
  
// Create a path
$draw->pathStart();
  
// Draw a star
$draw->pathMoveToRelative(350, 20); 
$draw->pathLineToRelative(40, 60); 
$draw->pathLineToRelative(80, 20); 
$draw->pathLineToRelative(-80, 30); 
$draw->pathLineToRelative(30, 60); 
$draw->pathLineToRelative(-50, -20); 
$draw->pathLineToRelative(-50, 40); 
$draw->pathLineToRelative(10, -70); 
$draw->pathLineToRelative(-50, -10); 
$draw->pathLineToRelative(50, -30); 
$draw->pathLineToRelative(20, -80); 
  
// End the path
$draw->pathFinish();
  
// Render the draw commands
$imagick->drawImage($draw);
  
// Show the output
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

chevron_right


Output:

Reference: https://www.php.net/manual/en/imagickdraw.pathlinetorelative.php




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.