Open In App
Related Articles

PHP | ImagickDraw translate() Function

Improve Article
Improve
Save Article
Save
Like Article
Like

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:




<?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();
?>


Output:
translate()

Program 2:




<?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();
?>


Output:

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


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks 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!

Last Updated : 30 Aug, 2019
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials