Last active
June 10, 2022 11:47
Revisions
-
conficient revised this gist
Jun 10, 2022 . No changes.There are no files selected for viewing
-
conficient created this gist
Jun 10, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ @* Creates a Gravatar image using Bootstrap styling from email address *@ <img class="rounded-circle" src="@url" /> @code { [Parameter] public string Email { get; set; } [Parameter] public int Size { get; set; } = 24; protected override void OnParametersSet() { // create hash var bytes = System.Text.Encoding.UTF8.GetBytes(Email.ToLower()); var hash = System.Security.Cryptography.MD5.HashData(bytes); var hex = string.Join("", hash.Select(x => x.ToString("x2"))); url = $"https://www.gravatar.com/avatar/{hex}?s={sizeClean}"; } const int minSize = 8; private int sizeClean => Size>= minSize ? Size: minSize; private string url = null; }