Use PHP to display Gravatar images

All URLs on Gravatar are based on the use of the hashed value of an email address. According to their best practice you should:

  1. Trim leading and trailing whitespace from an email address
  2. Force all characters to lower-case
  3. md5 hash the final string

Of course in PHP this is trivial as the following function shows:

function fetchGravatar() {
$fetchHash = md5(strtolower(trim('your_email.address.com')));
$GravatarImage = 'http://www.gravatar.com/avatar/' . $fetchHash;
return $GravatarImage;
}

Profiles are also available if you require them.

Leave a Reply

Your email address will not be published. Required fields are marked *