try{
$src = imagecreatefromjpeg('https://graph.facebook.com/'.$jsonfriends["data"][$randf]["id"].'/picture');
} catch (Exception $z){
$src = imagecreatefromgif('https://graph.facebook.com/'.$jsonfriends["data"][$randf]["id"].'/picture');
}
In the above code, when the code in the ‘try’ block fails, the control is not passing to the ‘catch’ block. I’m getting output as error as https://graph.facebook.com/xxxxxx/picture is not a valid JPEG. Actually, if its not a JPEG, it would be GIF in this context. So can anyone help me regarding this?
imagecreatefromjpegdoesn’t throw an exception if it fails. For more information on that, see PHP: How to manage errors gracefully?.You’d be better off using a function mentioned in the comments of the PHP documentation of the function:
This way, you avoid the problem altogether, as it simply doesn’t try to parse the file as a JPEG if it isn’t one.