Hey guys. I've been working on this problem and have used the code above but made it actually work. What I wanted to do is show a local avatar ONLY if the user doesn't have an account on Gravatar (free CDN == delicious).
Using this function may add time to your pageload. What it does is during PHP execution it fetches the proposed gravatar url using wp_get_http_headers() and returns the HTTP headers (you can inspect the http headers for a file in Firefox using the Firebug plugin). It then checks for 'content-disposition' in those headers.
SO: If you have a lot of gravatars you are checking the pageload will have to wait for PHP to check the headers of each file, THEN once it has determined that there is/isn't a gravatar account and the user recieves the html, the browser will still have to download the gravatar images from the server. If there are a lot then it could take a long long time.
What Chaoskaiser was saying about using hooks is that if you can avoid checking the gravatars on every pageload then it is very valuable to do so for speed.
She recommended adding your own plugin function to the post_comment hook, where you could make a note at the moment the comment is saved as to whether the user has a gravatar or not, that way subsequent pageloads wouldn't be a problem. This is a bit hairy as a recommendation though, because editing the wp_commetns tabel is a bad idea and I can't think of other good places for it.
Personally, I'm using this only for my actuall user accounts, so i'm running a cron that checks every user and saves their status (has_gravatar) in the wp_usermeta table so that I don't have to check the gravatar every time.
Another option that might be good is to add something to the comments form such that only RIGHT AFTER they post a comment and are brought back to the comment form do you do the check, then, if they dont' have a gravatar, you put a big link right above their comment saying "you have no image! Go to Gravatar.com and sign up for free!"
About testing the actual header responses I'm not sure what Chaoskaiser was getting at with the 200/302 response values, but in my testing there was no 'response' element at all. Luckily she seems to have hit the nail with 'content-disposition' which is only there for gravatars with actual accounts. So my function only uses that one to tell if the person has a gravatar.
function gv_validate_gravatar($user_id) {
// Mine is just for user_id, you can work out dealing with emails as well for yourself.
$user = get_userdata($user_id);
// Craft a potential url and test its headers
$email = $user->user_email;
$hash = md5($email);
$uri = 'http://www.gravatar.com/avatar/' . $hash . '?d=identicon&r=any&size=80';
$headers = wp_get_http_headers($uri);
// Check the headers
if (!is_array($headers)) :
$has_valid_avatar = FALSE;
elseif (isset($headers["content-disposition"]) ) :
$has_valid_avatar = TRUE;
else :
$has_valid_avatar = FALSE;
endif;
return $has_valid_gravatar;
}