Last active
December 5, 2016 09:13
-
-
Save rise-worlds/8680ff46e2beaa56c1db479029bf01c1 to your computer and use it in GitHub Desktop.
use gravatar.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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