Sunday, September 22, 2024
Google search engine
HomeLanguagesPHP | ImagickDraw pathMoveToRelative() Function

PHP | ImagickDraw pathMoveToRelative() Function

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

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