Skip to content
Related Articles

Related Articles

PHP | ImagickDraw clone() Function
  • Last Updated : 20 Dec, 2019

The ImagickDraw::clone() function is an inbuilt function in PHP which is used to make an exact copy of the specified ImagickDraw object.

Syntax:

ImagickDraw ImagickDraw::clone( void )

Parameters: This function doesn’t accepts any parameter.

Return Value: This function returns the exact copy of the specified ImagickDraw object on success or error on failure.

Exceptions: This function throws ImagickException on error.



Below programs illustrate the ImagickDraw::clone() 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 text properties
$draw->setFontSize(100);
$draw->setFillColor('blue');
  
// Apply the annotation() function
$draw->annotation(50, 150, 'GeeksforGeeks');
  
// Create a new ImagickDraw object
$copied = new ImagickDraw();
  
// Copy the object
$copied = $draw->clone();
  
//  Render the draw commands from copied object
$imagick->drawImage($copied);
  
// 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();
  
// Draw a circle
$draw->circle(200, 100, 100, 100);
  
// Create a new ImagickDraw object
$copied = new ImagickDraw();
  
// Copy the object
$copied = $draw->clone();
  
//  Render the draw commands from copied object
$imagick->drawImage($copied);
  
// Add a border
$imagick->borderImage('black', 1, 1);
  
// Show the output
$imagick->setImageFormat("png");
header("Content-Type: image/png");
  
echo $imagick->getImageBlob();
?>

Output:

Reference: https://www.php.net/manual/en/imagickdraw.clone.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 :