Wednesday, July 3, 2024
HomeLanguagesPhpPHP | ImagickDraw pathCurveToAbsolute() Function

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:




<?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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Nicole Veronica Rubhabha
Nicole Veronica Rubhabha
A highly competent and organized individual DotNet developer with a track record of architecting and developing web client-server applications. Recognized as a personable, dedicated performer who demonstrates innovation, communication, and teamwork to ensure quality and timely project completion. Expertise in C#, ASP.Net, MVC, LINQ, EF 6, Web Services, SQL Server, MySql, Web development,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments