Reputation: 185
I use imagick to create thumbnails of PDF files, but in some cases imagic returns a Fatal Error. I am looking for a way to know when the fatal error occurs. Something like this:
function MakeThumb($source) {
if($im = new imagick($source)) {
//Generate thumbnail
return($thumb);
} else {
return 'no_thumb.png'; // then we will not tray again later.
}
}
Upvotes: 1
Views: 5935
Reputation: 1636
You could do something like this
function MakeThumb($source) {
try {
//throw exception if can't create file
if(!$im = new imagick($source) {
throw new Exception('Count not create thumb');
}
//ok if got here
return($thumb);
} catch (Exception $e) {
return 'no_thumb.png';
}
}
I haven't tested it,but by using Try Catch
, you can make it work
http://php.net/manual/en/language.exceptions.php
Upvotes: 2