Gravatar : Is there a default image?

You can also use a custom URL for the default/fallback avatar. However, the custom URL must point to a publicly available image or else it wont show. You can learn more here and at gravatar.com.

Here is a PHP function I use to when working with gravatar images.

function myprefix_get_gravatar_url( $email, $default='mm', $size=92 )
{
    $email = md5( strtolower( trim( $email ) ) );
    $default = urlencode( $default );
    $size = (int)$size;

    $url = 'http://www.gravatar.com/avatar/';
    if ( is_ssl() )
        $url = 'https://secure.gravatar.com/avatar/';

    return $url.$email."?d=".$default."&s=".$size;
}

Example usage:

$img2x = myprefix_get_gravatar_url( 
    '[email protected]',
    'https://www.google.com/images/srpr/logo11w.png',
    184
);

Gravatar describe the options for default images here: http://en.gravatar.com/site/implement/images/

You can select which option you want by adding the appropriate name/value pair to your url. For example, you could use "mystery person" (d=mp) which looks like this:

The above image was created with the url http://www.gravatar.com/avatar/?d=mp. Note that the email hash string has been omitted but normally you would include it as part of the request.

Options listed at the above link:

  • 404: do not load any image if none is associated with the email hash, instead return an HTTP 404 (File Not Found) response
  • mp: (mystery-person) a simple, cartoon-style silhouetted outline of a person (does not vary by email hash)
  • identicon: a geometric pattern based on an email hash
  • monsterid: a generated 'monster' with different colors, faces, etc
  • wavatar: generated faces with differing features and backgrounds
  • retro: awesome generated, 8-bit arcade-style pixelated faces
  • robohash: a generated robot with different colors, faces, etc
  • blank: a transparent PNG image (border added to HTML below for demonstration purposes)

As you would hope, using the size option s=<pixels> also changes the size of the default image.

enter image description here

The above image was created with http://www.gravatar.com/avatar/?d=retro&s=32

Thanks to @Alireza Rezaee for the updated image types.


To select a default image, you can use the d parameter:

http://www.gravatar.com/avatar/3b3be63a4c2a439b013787725dfce802?d=identicon

Or without a hash:

http://www.gravatar.com/avatar/?d=identicon

Or without the d parameter:

http://www.gravatar.com/avatar

Source: gravatar.com.


Not really, no. That is missing the point of the Gravatar service. It is designed so that your users can register their email address(es) and associate a gravatar image with it/them. Your site (and other sites) can then query Gravatar to give back the image which is associated with the email address in question.

If you want an image showing for users who do not even enter an email address on your website, you have two solutions that I can see:

  1. Do it in your own code. When you are dealing with a user who has no email address, you can just output a default image of your own choosing. Of course, this means it will not be done using a gravatar address and it'll be something you'll need to be serving yourself.
  2. Register an email address yourself dedicated to users who do not have/enter their own. For example, you could register something like [email protected] and then register this with the Gravatar service and associate your chosen default image with this. Your own app code will still need to output the appropriate gravatar URL substituting this email address in place of the user's non-existant one when constructing the image URL, but it will allow you to use a gravatar URL which is something you have asked for.