PHP | Imagick setProgressMonitor() Function
Last Updated :
13 Dec, 2019
The Imagick::setProgressMonitor() function is an inbuilt function in PHP which is used to set a callback function that will be called during the processing of the Imagick image if something goes wrong. You can use this function to pause a program before proceeding further.
Syntax:
bool Imagick::setProgressMonitor( callable $callback )
Parameters: This function accepts a single parameter $callback which holds the callback function.
Return Value: This function returns TRUE on success.
Exceptions: This function throws ImagickException on error.
Below programs illustrate the Imagick::setProgressMonitor() function in PHP:
Program 1:
<?php
$imagick = new Imagick();
$imagick ->newImage(640, 480, "blue" );
$status = 'Not cancelled' ;
$text = '<br>' ;
$callback = function ( $offset , $span ) use (& $status , $text ) {
$status = "Callback is called" . $text ;
return false;
};
$imagick ->setProgressMonitor( $callback );
try {
$imagick ->charcoalImage( $x , $y );
echo "Callback function wasn't called." ;
} catch (\Exception $e ) {
echo $status ;
}
?>
|
Output:
Callback is called
Program 2:
<?php
$imagick = new Imagick();
$imagick ->newImage(600, 400, "white" );
$status = 'Not cancelled' ;
$text = '<br>' ;
$callback = function ( $offset , $span ) use (& $status , $text ) {
$status = "Callback is called" . $text ;
return true;
};
$imagick ->setProgressMonitor( $callback );
try {
$x = 20;
$y = 5;
$imagick ->charcoalImage( $x , $y );
echo "Callback function wasn't called." ;
} catch (\Exception $e ) {
echo $status ;
}
?>
|
Output:
Callback function wasn't called.
Reference: https://www.php.net/manual/en/imagick.setprogressmonitor.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...