To check image existence you can use below function. You just need to pas the image URL in this function and it will return true or false, this way you can identify and show image based on it's existence.
//Check whether image exists or not
function UR_exists($url){
if (@getimagesize($url)) {
return true;
} else {
return false;
}
}