Assuming you are talking about a scenario where you are attempting to fetch the image over HTTP / HTTPS ...
The simple approach is to just attempt to fetch the image. Then you check the response to see what the response status code is and what the content type is. If they 200 and "image/png" respectively then you have the image. If the status code is 404 then the image does not exist. If neither, then it is a reasonable assumption that "something has gone wrong" at the server end.
The linked question has code for doing this kind of thing.
The problem is that you are somewhat dependent on what the server does when you attempt to fetch an image that isn't there. It could plausibly:
- substitute a default image of its own
- return an error page, with or without setting a 404 status code
- redirect you to an error page, which means that the status code would be a 3xx,
- fail, resulting in a 5xx response, or even
- seem to succeed but return an empty body, or a body whose actual contents doesn't match the response "content-type" header.
If you implemented the server, or you are dealing directly with the implementers, you can make assumptions about what it will do. But if your code has to work against any server, then it needs to be more complicated ... and more defensive.