PHP | ImagickDraw clear() Function
Last Updated :
19 Dec, 2019
The ImagickDraw::clear() function is an inbuilt function in PHP which is used to clear the ImagickDraw object of any accumulated commands, and resets the settings it contains to their defaults.
Syntax:
bool ImagickDraw::clear( void )
Parameters: This function doesn’t accepts any parameter.
Return Value: This function returns TRUE on success.
Exceptions: This function throws ImagickException on error.
Below given programs illustrate the ImagickDraw::clear() function in PHP:
Program 1:
<?php
$imagick = new Imagick();
$imagick ->newImage(800, 250, 'black' );
$draw = new ImagickDraw();
$draw ->setFontSize(110);
$draw ->setFillColor( 'green' );
$draw ->annotation(20, 120, 'Random Content' );
$draw ->clear();
$draw ->setFontSize(110);
$draw ->setFillColor( 'white' );
$draw ->annotation(20, 120, 'New Content' );
$imagick ->drawImage( $draw );
$imagick ->setImageFormat( "png" );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:
Program 2:
<?php
$imagick = new Imagick();
$imagick ->newImage(800, 250, 'white' );
$draw = new ImagickDraw();
$draw ->setFontSize(110);
$draw ->setFillColor( 'green' );
$draw ->annotation(20, 120, 'GeeksforGeeks' );
$draw ->clear();
$imagick ->drawImage( $draw );
$imagick ->setImageFormat( "png" );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:
This will throw ImagickException because $draw is emptied by clear(), thus cannot be drawn.
Reference: https://www.php.net/manual/en/imagickdraw.clear.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...