Conditional avatar

A few months ago I wrote a discussion over at this WordPress.org thread regarding this. Check it out: http://wordpress.org/support/topic/custom-avatar-4?replies=5

Here is the code you’ll need in the template you want your avatars:

   <?php
    $uploads = wp_upload_dir(); //WordPress upload path
    $uploads_url = ( $uploads['baseurl'] ); //full url of upload dir
    $uploads_dir = ( $uploads['basedir'] ); //full path of upload dir
    $user_id = $post->post_author; //id of author (if used in loop)
    $avatar_filename = user_avatar_avatar_exists($user_id ); //function from plugin

if (file_exists($uploads_dir.'/avatars/'.$user_id ."https://wordpress.stackexchange.com/".$avatar_filename)) {
    echo ('<img src="https://wordpress.stackexchange.com/questions/116001/.$uploads_dir."/avatars/'.$user_id ."https://wordpress.stackexchange.com/".$avatar_filename.' class="user-avatar"/>');
}
else {
    echo get_avatar( get_the_author_meta('user_email'), $size="60");
} ?>

EDIT: To show nothing when the gravar is empty use this (source above thread):

   <?php
    $uploads = wp_upload_dir(); //WordPress upload path
    $uploads_url = ( $uploads['baseurl'] ); //full url of upload dir
    $uploads_dir = ( $uploads['basedir'] ); //full path of upload dir
    $user_id = $post->post_author; //id of author (if used in loop)
    $avatar_filename = user_avatar_avatar_exists($user_id ); //function from plugin

   $hash = md5(strtolower(trim($user->user_email)));
   $uri = 'http://www.gravatar.com/avatar/' . $hash . '?d=404';
   $headers = @get_headers($uri);


if (((preg_match("|200|", $headers[0])) || (file_exists($uploads_dir.'/avatars/'.$user_id ."https://wordpress.stackexchange.com/".$avatar_filename))) {

if (file_exists($uploads_dir.'/avatars/'.$user_id ."https://wordpress.stackexchange.com/".$avatar_filename)) {
    echo ('<img src="https://wordpress.stackexchange.com/questions/116001/.$uploads_dir."/avatars/'.$user_id ."https://wordpress.stackexchange.com/".$avatar_filename.' class="user-avatar"/>');
}
else {
    echo get_avatar( get_the_author_meta('user_email'), $size="60");
} 

} ?>