Gravatar

Just a little method to get an url to a public avatar image from gravatar.com.

readonly static MD5CryptoServiceProvider _md5 = new MD5CryptoServiceProvider();  
static Uri GetGravatar(string email)  
{
    const string uriFormat = "http://www.gravatar.com/avatar/{0}.jpg";
    StringBuilder sb = new StringBuilder();            
    foreach(byte ch in _md5.ComputeHash(
        Encoding.ASCII.GetBytes(email.Trim().ToLowerInvariant())
        ))
        sb.AppendFormat("{0:x2}", ch);
    return new Uri(string.Format(uriFormat, sb.ToString()));
}
Google
m@kli.dk @klinkby RSS feed  GitHub