Gravatar API - Gravatar - Globally Recognized Avatars

What Is Gravatar?

A Gravatar is a Globally Recognized Avatar. You upload it and create your profile just once, and then when you participate in any Gravatar-enabled site, your Gravatar image will automatically follow you there.

PHP Image Requests

Implementing gravatars with PHP is quite simple. PHP provides strtolower(), md5(), and urlencode() functions, allowing us to create the gravatar URL with ease. Assume the following data:

$email = "[email protected]";

$default = "";

$size = 40;
You can construct your gravatar url with the following php code:
$grav_url = "" . md5( strtolower( trim( $email ) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size;

Once the gravatar URL is created, you can output it whenever you please:


Example Implementation

This function will allow you to quickly and easily insert a Gravatar into a page using PHP:

* Get either a Gravatar URL or complete image tag for a specified email address.

* @param string $email The email address

* @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ]

* @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]

* @param string $r Maximum rating (inclusive) [ g | pg | r | x ]

* @param boole $img True to return a complete IMG tag False for just the URL

* @param array $atts Optional, additional key/value attributes to include in the IMG tag

* @return String containing either just a URL or a complete image tag

* @source


function get_gravatar( $email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array() ) {

$url = '';

$url .= md5( strtolower( trim( $email ) ) );

$url .= "?s=$s&d=$d&r=$r";

if ( $img ) {

$url = '

foreach ( $atts as $key => $val )

$url .= ' ' . $key . '="' . $val . '"';

$url .= ' />';


return $url;


Existing Implementations

Developer Resources

Gravatar 'APIs' require no authentication, and are all based around simple HTTP GET requests. Use the links below to find out more about constructing request URLs, different implementation options and more.

Gravatar URLs

Learn about how to generate the URLs required to request Gravatar Images and Profile data.

Gravatar Images

Gravatar Profiles



About The Massive Technolab

Who We Are

Massive Technolab is a Leading IT services Company in India that expertise in web Development, Web Design and SEO at affordable rates.

Leave a Comment

comments powered by Disqus