Suppose you have a thumbnail generator script that accepts source images in the form of a URL. Is there a way to detect if the source URL is \"broken\" - whether nonexistent
The only really reliable way is to request the image using file_get_contents(), and finding out its image type using getimagesize().
Only if getimagesize()
returns a valid file type, can you rely that it is in fact a valid image.
This is quite resource heavy, though.
You could consider not doing any server-side checks at all, and adding an onerror
JavaScript event to the finished image resource: