PHP | ImagickDraw pathCurveToAbsolute() Function

The ImagickDraw::pathCurveToAbsolute() function is an inbuilt function in PHP which is used to draw a cubic Bezier curve which is a parametric curve. This function draws a curve from the current point to (x, y) using beginning control point (x1, y1) to ending control point (x2, y2). In the last command, the new current point becomes the final (x, y) coordinate pair used in the polybezier.

Syntax:

bool ImagickDraw::pathCurveToAbsolute( float $x1, float $y1,
                            float $x2, float $y2, float $x, float $y )

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

  • $x1: It specifies the x-coordinate of first control point.
  • $y1: It specifies the y-coordinate of first control point.
  • $x2: It specifies the x-coordinate of second control point.
  • $y2: It specifies the y-coordinate of second control point.
  • $x: It specifies the x-coordinate of curve end.
  • $y: It specifies the y-coordinate of curve end.

Return Value: This function returns TRUE on success.

Below programs illustrate the ImagickDraw::pathCurveToAbsolute() 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();
  
$draw->setFillColor('white');
  
// Set the stroke color
$draw->setStrokeColor('green');
  
// Set the stroke width
$draw->setStrokeWidth(5);
  
// Start a path
$draw->pathStart();
$draw->pathCurveToAbsolute(50, 100, 180, 200, 1360, 200);
$draw->pathFinish();
  
// Set the stroke color
$draw->setStrokeColor('red');
  
// Draw curve to absolute (with pathClose())
$draw->pathStart();
$draw->pathCurveToAbsolute(500, 20, 80, 40, 60, 900);
$draw->pathClose();
$draw->pathFinish();
  
// Set the stroke color
$draw->setStrokeColor('blue');
  
// Draw curve to absolute (with pathClose())
$draw->pathStart();
$draw->pathCurveToAbsolute(50, 50, 80, 20, 1360, 200);
$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();
?>

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, 'black');
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Set the stroke color
$draw->setStrokeColor('white');
  
// Set the stroke width
$draw->setStrokeWidth(5);
  
// Start a path
$draw->pathStart();
  
// Draw curve to absolute
$draw->pathCurveToAbsolute(50, 400, 560, 700, 160, 20);
$draw->pathCurveToAbsolute(1000, 40, 560, 70, 60, 300);
  
// Close 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.pathcurvetoabsolute.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.