Open In App

PHP | ImagickDraw __construct() Function

Last Updated : 23 Dec, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The ImagickDraw::__construct() function is an inbuilt function in PHP which is used to initialize a ImagickDraw object.

Syntax:

bool ImagickDraw::__construct( void )

Parameters: This function doesn’t accept any parameter.

Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

Below given programs illustrate the ImagickDraw::__construct() function in PHP:

Program 1:




<?php
  
// Create a new imagick object
$imagick = new Imagick();
  
// Create a image on imagick object
$imagick->newImage(800, 250, 'blue');
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Draw a rectangle
$draw->rectangle(200, 50, 600, 200);
  
// Render the draw commands
$imagick->drawImage($draw);
  
// 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, 'green');
   
// Create a new ImagickDraw object
$draw = new ImagickDraw();
   
// Draw a line
$draw->line(0, 0, 800, 250);
   
// Render the draw commands
$imagick->drawImage($draw);
   
// Show the output
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>


Output:

Reference: https://www.php.net/manual/en/imagickdraw.construct.php



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads