
Photo by bas:ilSo, we have a website that displays images from an external source based upon a URL. For various reasons, sometimes the external source does not have a valid image for the request. In order not to show a broken image to the use, we need to validate that the image is valid.
Thanks to Google (NOT Bing. haha) we found a great little approach that was quickly placed into a Drupal template file.
if (@GetImageSize("http://www.testdomain.com/testimage.gif")) {
echo "image exists";
} else {
echo "image does not exist";
}
And according to the site, if you do not have GD installed you can try this code:
if (@fclose(@fopen("http://www.testdomain.com/testimage.gif", "r"))) {
echo "image exists";
} else {
echo "image does not exist";
}
via Developer Blog » Check if external image exists.
Popularity: 4% [?]