Well, $img will always be set when the code reaches your if() statement, regardless of whether or not the image was actually retrieved. What you want to do is test if it has a value of FALSE, or simply:
if(!$img) {
Now, I'm sure someone will come along and say, "That doesn't test if it's false, that just tests if it's FALSE, NULL, 0, "0", ..." and suggest instead:
if($img === FALSE) {
or something, but... whatever. :p Of course, yet another suggestion might be to create your own error handler instead of using the '@' error suppressor, though I don't see anything wrong with it in this context.