Add Gravatar to your web sites using PHP & C#

Gravatar (an abbreviation for globally recognized avatar) is a service for providing globally unique avatars which was created by Tom Preston-Werner. On Gravatar, users can register an account based on their email address, and upload an avatar to be associated with the account. Gravatar plugins are available for popular blogging software; when the user posts a comment on such a blog that requires an e-mail address, the blogging software checks whether that e-mail address has an associated avatar at Gravatar.

PHP:


function GetAvatar($email)
{
   $emailMD5 = md5($email);
   $gravatarURL = "http://www.gravatar.com/avatar/" . $emailMD5 . ".jpg";
   $html="<img src='$gravatarURL' />"; return $html;
}

C#:


public string GetAvatar(string Email)
{
   string emailMd5 = Utilities.Encryption.MD5.ComputeHash(Email.Trim().ToLower()).ToLower();
   string gravatarURL = "http://www.gravatar.com/avatar/" + emailMD5 + ".jpg";
   string html = "<img src='" + $gravatarURL + "' />"; return html;
}
 

6 thoughts on “Add Gravatar to your web sites using PHP & C#”

Leave a Reply

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