PHP | ImagickDraw __construct() Function
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
Contact Us