Skip to content
Related Articles

Related Articles

PHP | ImagickDraw translate() Function
  • Difficulty Level : Easy
  • Last Updated : 30 Aug, 2019

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

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :