Skip to content

Commit

Permalink
Format SvgIdenticonGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
TheArcaneBrony committed Apr 4, 2024
1 parent 956b734 commit ca63a0d
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions ArcaneLibs/SvgIdenticonGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ namespace ArcaneLibs;

public class SvgIdenticonGenerator {
// based on https://github.com/stewartlord/identicon.js/blob/master/identicon.js

public string BackgroundColor { get; set; } = "#FEFEFEFF";
public float Saturation { get; set; } = 0.7f;
public float Brightness { get; set; } = 0.5f;
public string? ForegroundColor { get; set; }


public string Generate(string identity) {
var hash = SHA1.HashData(identity.AsBytes().ToArray());



var hashArray = new byte[hash.Length];
for (var i = 0; i < hash.Length; i++) {
hashArray[i] = hash[i];
Expand All @@ -39,13 +37,12 @@ public string Generate(string identity) {
svg += "</svg>";
return svg;
}

public string GenerateAsBase64(string identity) {
return Convert.ToBase64String(Generate(identity).AsBytes().ToArray());
}

public string GenerateAsDataUri(string identity) {
return $"data:image/svg+xml;base64,{GenerateAsBase64(identity)}";
}

}

0 comments on commit ca63a0d

Please sign in to comment.