Open In App

PHP | ImagickDraw pathMoveToRelative() Function

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

The ImagickDraw::pathMoveToRelative() function is an inbuilt function in PHP which is used to start a new sub-path at the given coordinate using relative coordinates. The current point then becomes the specified coordinate. This function is used for setting initial coordinates before starting drawing anything.

Syntax:

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

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

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

Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

Below given programs illustrate the ImagickDraw::pathMoveToRelative() 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();
  
// Set the stroke width
$draw->setStrokeWidth(30);
  
$draw->pathStart();
  
// Setting the stating point to (400, 100)
$draw->pathMoveToRelative(400, 100);
  
// Setting the end point to (500, 100)
$draw->pathLineToHorizontalAbsolute(500);
$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, 'white');
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Set the stroke width
$draw->setStrokeWidth(30);
  
$draw->setFillColor('red');
  
$draw->pathStart();
  
// Setting the stating point to (400, 100), draw a rectangle
$draw->pathMoveToRelative(400, 100);
$draw->pathLineToAbsolute(400, 200);
$draw->pathLineToAbsolute(300, 200);
$draw->pathLineToAbsolute(300, 100);
  
$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.pathmovetorelative.php



Similar Reads

PHP | ImagickDraw getTextAlignment() Function
The ImagickDraw::getTextAlignment() function is an inbuilt function in PHP which is used to get the alignment applied when annotating with text. It helps to format the text by making it stick to left, right or middle. Syntax: int ImagickDraw::getTextAlignment( void ) Parameters: This function doesn’t accept any parameter. Return Value: This functio
2 min read
PHP | ImagickDraw scale() Function
The ImagickDraw::scale() function is an inbuilt function in PHP which is used to adjust the scaling factor to apply in the horizontal and vertical directions to the current coordinate space. Syntax: bool ImagickDraw::scale( $x, $y ) Parameters: This function accepts two parameter as mentioned above and described below: $x: This parameter is used to
2 min read
PHP | ImagickDraw polygon() Function
The ImagickDraw::polygon() function is an inbuilt function in Imagick library in PHP which is used to draw a polygon using the specified array of coordinates. Syntax: bool ImagickDraw::polygon( $coordinates ) Parameters: This function accepts single parameter $coordinates of array type. It is used to hold the set of points.Return Value: This functi
2 min read
PHP | ImagickDraw roundRectangle() Function
The ImagickDraw::roundRectangle() function is an inbuilt function in Imagick library of PHP which is used to draw a rounded rectangle. Syntax: bool ImagickDraw::roundRectangle( $x1, $y1, $x2, $y2, $rx, $ry ) Parameters: This function accept six parameters as mentioned above and described below: $x1: This parameter takes the value of x coordinate of
2 min read
PHP | ImagickDraw arc() Function
The ImagickDraw::arc() function is an inbuilt function in Imagick library of PHP which is used to draw an arc. Syntax: bool ImagickDraw::arc( $sx, $sy, $ex, $ey, $sd, $ed ) Parameters: This function accepts six parameters as mentioned above and described below: $sx: This parameter takes the value of starting x-ordinate. $sy: This parameter takes th
1 min read
PHP | ImagickDraw circle() Function
The ImagickDraw::circle() function is an inbuilt function in Imagick library of PHP which is used to draw a circle. Syntax: bool ImagickDraw::circle( $ox, $oy, $px, $py ) Parameters: This function accepts four parameters as mentioned above and described below: $ox: This parameter takes the value of origin x-coordinate. $oy: This parameter takes the
1 min read
PHP | ImagickDraw bezier() Function
The ImagickDraw::bezier() function is an inbuilt function in Imagick library of PHP which is used to draw bezier curve. Syntax: bool ImagickDraw::bezier( $coordinates ) Parameters: This function accepts a single parameter as the multidimensional array which takes the points through which curve is to be made. Return Value: This function does not ret
1 min read
PHP | ImagickDraw rectangle() Function
The ImagickDraw::rectangle() function is an inbuilt function in Imagick library of PHP which is used to draw a rectangle. Syntax: bool ImagickDraw::rectangle( $x1, $y1, $x2, $y2 ) Parameters: This function accepts four parameters as mentioned above and described below: $x1: This parameter takes the value of x coordinate of the top left corner. $y1:
1 min read
PHP | ImagickDraw line() Function
The ImagickDraw::line() function is an inbuilt function in Imagick library of PHP which is used to draw a line. This function draw the line using the current stroke color, stroke opacity, and stroke width. Syntax: bool ImagickDraw::line( $sx, $sy, $ex, $ey ) Parameters: This function accepts four parameters as mentioned above and described below: $
1 min read
PHP | ImagickDraw point() Function
The ImagickDraw::point() function is an inbuilt function in Imagick library of PHP which is used to draw a point. This function uses current stroke color and stroke thickness at the specified coordinates. Syntax: bool ImagickDraw::point( $x, $y ) Parameters: This function accepts two parameters as mentioned above and described below: $x: This param
1 min read