Wednesday, November 20, 2024
Google search engine
HomeLanguagesPHP | ImagickDraw clone() Function

PHP | ImagickDraw clone() Function

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, 'neveropen');
  
// 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

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