example:
Code: Select all
function readImage($wand, $filename) {
// read current error reporting
$current_error_reporting = ini_get("error_reporting");
// diable error reporting
error_reporting(0);
// change error handler function
set_error_handler("magickErrorHandler");
try {
$result = MagickReadImage($wand, $filename);
} catch (Exception $e) {
// restore error handler and throw exception
error_reporting($current_error_reporting);
restore_error_handler();
throw $e;
}
// restore error handling and return result
error_reporting($current_error_reporting);
restore_error_handler();
return $result;
}
function magickErrorHandler($errno, $errmsg, $filename, $linenum, $vars) {
if (strpos($errmsg, "no decode delegate for this image"))
$msg = "unknown format";
else
$msg = $errmsg;
throw new Exception($msg, $errno);
}
Code: Select all
try{
$srcMagickWand = NewMagickWand();
if (!readImage($srcMagickWand , "/tmp/bleh.txt"))
die("something else went wrong.\n");
} catch (Exception $e) {
print "fatal error: ".$e->getMessage()."\n";
}
cheers