There’s a PHP function, called getimagesize(), it can do what you’re looking for.
For example:
$url is the image url
$imgsize = @getimagesize( $url ); // @ is needed to prevent error messages
if ( $imgsize // is the variable is not false
&& $imgsize[0] > 0 // and if the img width is larger than 0
&& $imgsize[1] > 0 // and if the img height is larger than 0
)
{
// your file exists, write your code here
}
else
{
// your file is not available, write your code here
}
If you specify it more, I can make this look better for example into template.