+

PHP Imagick setProgressMonitor () function

Syntax:
bool Imagick::setProgressMonitor (callable $callback)
Parameters:This function takes one parameter $callback,which contains a callback function.Return value:This function returns TRUE on success.Exceptions:This function throws an ImagickException on error.The following programs illustrate the Imagick::setProgressMonitor() function in PHP:Program 1:  
// Create a new Imagick object $imagick = new Imagick();  
// Create image in Imagick $imagick -> newImage (640, 480, "blue" ); $status = ` Not canceled` ; $text = `< br > ` ;  
// callback function $callback = function ( $offset , $span ) use (& amp; $status , $text ) { $status = "Callback is called " . $text ; return false; };  
// Install progress monitor $imagick -> setProgressMonitor ( $callback ); try { // $x and $y are not defined, so call // callback is expected here $imagick -> charcoalImage ( $x , $y ); echo "Callback function wasn` t called. " ; } catch (Exception $e ) { echo $status ; }
?>
Output:
Callback is called
Program 2: < table border = "0" cellpadding = "0" cellspacing = "0">  
// Create a new Imagick object $imagick = new Imagick() ;  
// Create image in Imagick $imagick -> newImage (600, 400, "white" ); $status = ` Not canceled` ; $text = `< br > ` ;  
// callback function $callback = function ( $offset , $span ) use (& amp; $status , $text ) { $status = "Callback is called " . $text ; return true; };  
// Install progress monitor $imagick -> setProgressMonitor ( $callback ); try { // $x and $y are defined, thus calling // callback is expected here $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.
Link: https://www.php.net/manual/en/imagick.setprogressmonitor.php
Get Solution for free from DataCamp guru