Gravatar is a website that, after registering and adding an email, allows you to set an avatar (image) associated to that email, so that sites that query them for gravatar images will return your same image to all of them.
Although Community Server doesn't stores emails of user comments, I wanted to see how the avatars are obtained from Gravatar.com.
The url you have to build is well explained in their website, so I will just place a basic C# code that calculates the MD5 hash and inserts it on the url:
string email = "me@mydomain.com";
System.Security.Cryptography.MD5CryptoServiceProvider CryptoService;
byte[] InputBytes = System.Text.Encoding.ASCII.GetBytes(email.Replace(" ", "").ToLower());
string emailHash;
CryptoService = new System.Security.Cryptography.MD5CryptoServiceProvider();
InputBytes = CryptoService.ComputeHash(InputBytes);
emailHash = BitConverter.ToString(InputBytes).Replace("-", "");
string gravatarURL = string.Format("http://www.gravatar.com/avatar/{0}.jpg", emailHash);
And we're done, the final URL pointing to a gravatar.
The following image gets one of my email adresses' gravatar (if I change it from the cigar dog one day on my gravatar account, it will change automatically):
There are options (as querystring parameters) as getting the image in a specific resolution, or getting the identicon.
Tags: Development