Skip to content

Instantly share code, notes, and snippets.

@rise-worlds
Last active December 5, 2016 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rise-worlds/8680ff46e2beaa56c1db479029bf01c1 to your computer and use it in GitHub Desktop.
Save rise-worlds/8680ff46e2beaa56c1db479029bf01c1 to your computer and use it in GitHub Desktop.
use gravatar.com
public static class SignatureExtensions
{
static Dictionary<string, string> avatars = new Dictionary<string, string>();
public static string GetAvatar(this String email, int size = 75)
{
string key = email + "_" + size;
if (!avatars.ContainsKey(key))
{
string avatar = "//www.gravatar.com/avatar/";
MD5 md5Hasher = MD5.Create();
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(email));
StringBuilder builder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
builder.Append(data[i].ToString("x2"));
}
avatar += builder.ToString() + "?s=" + size;
avatars[key] = avatar;
}
return avatars[key];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment