PHP | ImagickDraw translate() Function

The ImagickDraw::translate() function is an inbuilt function in PHP which is used to apply a translation to the current coordinate system. It applies a translation to the current coordinate system which moves the coordinate system origin to the specified coordinate.

Syntax:

bool ImagickDraw::translate( $x, $y )

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

  • $x: This parameter is used to hold the value of x translation coordinate.
  • $y: This parameter is used to hold the value of y translation coordinate.

Return Value: This function does not return any value.

Below programs illustrates the ImagickDraw::translate() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// require_once('path/vendor/autoload.php');
  
// Create a ImagickDraw object to draw into.
$draw = new ImagickDraw();
  
// Set the stroke color
$draw->setStrokeColor('black');
  
// Set the Image Filled Color
$draw->setFillColor('red');
  
// Draw the circle
$draw->circle(250, 250, 100, 150);
   
// Set the Image Filled Color
$draw->setFillColor('green');
  
// Set the translation points
$draw->translate(90, 30);
  
// Draw the circle
$draw->circle(350, 350, 250, 350);
   
// Create new imagick object
$image = new Imagick();
  
// Set the dimensions of the image
$image->newImage(500, 500, 'white');
  
// Set the image format
$image->setImageFormat("png");
  
// Draw the image
$image->drawImage($draw);
header("Content-Type: image/png");
  
// Display the image
echo $image->getImageBlob();
?>

chevron_right


Output:
translate()

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// require_once('path/vendor/autoload.php');
   
// Create a ImagickDraw object to draw into.
$draw = new ImagickDraw();
   
// Set the Stroke color
$draw->setStrokeColor('black');
   
// Set the image filled color 
$draw->setFillColor('red');
$points = [['x' => 40 * 5, 'y' => 10 * 5], 
           ['x' => 70 * 5, 'y' => 50 * 5], 
           ['x' => 60 * 5, 'y' => 15 * 5], ];
   
// Draw the polygon
$draw->polygon($points);
   
// Set the image filled color 
$draw->setFillColor('green');
   
// Set the translation points
$draw->translate(10, 30);
$points = [['x' => 40 * 5, 'y' => 10 * 5], 
           ['x' => 70 * 5, 'y' => 50 * 5], 
           ['x' => 60 * 5, 'y' => 15 * 5], ];
   
// Draw the polygon
$draw->polygon($points);
   
// Set the image filled color 
$draw->setFillColor('blue');
   
// Set the translation points
$draw->translate(10, 30);
$points = [['x' => 40 * 5, 'y' => 10 * 5], 
           ['x' => 70 * 5, 'y' => 50 * 5], 
           ['x' => 60 * 5, 'y' => 15 * 5], ];
   
// Draw the polygon
$draw->polygon($points);
   
// Set the image filled color
$draw->setFillColor('yellow');
   
// Set the translation points
$draw->translate(10, 30);
$points = [['x' => 40 * 5, 'y' => 10 * 5], 
           ['x' => 70 * 5, 'y' => 50 * 5], 
           ['x' => 60 * 5, 'y' => 15 * 5], ];
   
// Draw the polygon
$draw->polygon($points);
   
// Create new imagick object
$image = new Imagick();
   
// Set the image dimensions
$image->newImage(400, 400, 'white');
   
// Set the image format
$image->setImageFormat("png");
   
// Draw the image 
$image->drawImage($draw);
header("Content-Type: image/png");
   
// Display the image
echo $image->getImageBlob();
?>

chevron_right


Output:

Reference: http://php.net/manual/en/imagickdraw.translate.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : nidhi_biet