Open In App

PHP | ImagickDraw pathCurveToAbsolute() Function

Last Updated : 17 Dec, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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:




<?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();
?>


Output:

Program 2:




<?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();
?>


Output:

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



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads