Monday, September 23, 2024
Google search engine
HomeLanguagesPHP | ImagickDraw pathCurveToRelative() Function

PHP | ImagickDraw pathCurveToRelative() Function

The ImagickDraw::pathCurveToRelative() function is an inbuilt function in PHP which is used to draw a cubic Bezier curve from the current point to (x, y) using (x1, y1) as the control point at the beginning of the curve and (x2, y2) as the control point at the end of the curve using relative coordinates.

Syntax:

bool ImagickDraw::pathCurveToRelative( 
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 starting control point.
  • $y1: It specifies the y-coordinate of starting control point.
  • $x2: It specifies the x-coordinate of ending control point.
  • $y2: It specifies the y-coordinate of ending control point.
  • $x: It specifies the ending x-coordinate.
  • $y: It specifies the ending y-coordinate.

Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

Below given programs illustrate the ImagickDraw::pathCurveToRelative() function in PHP:

Program 1:




<?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();
  
$draw->setFillColor('black');
  
// Set the stroke color
$draw->setStrokeColor('white');
  
// Draw curves to Quadratic Bezier Relative (without pathClose())
$draw->pathStart();
$draw->pathCurveToRelative(50, 250, 900, 20, 100, 300);
$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();
  
$draw->setFillColor('black');
  
// Set the stroke color
$draw->setStrokeColor('white');
  
// Draw curves to Quadratic Bezier Relative (with pathClose())
$draw->pathStart();
$draw->pathCurveToRelative(50, 250, 1900, 20, 100, 300);
$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.pathcurvetorelative.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!

RELATED ARTICLES

Most Popular

Recent Comments