public static async Task <byte[]> GenerateAsync( string avatarUrl, string username, string discriminator, string level, string reputation, string credits, string rank, string experience, float percentage, string themeColor) { using var avatar = new MagickImage(await ImageGeneration.Client.GetByteArrayAsync(avatarUrl)); using var image = new MagickImage(Template, PixelReadSettings); avatar.Resize(142, 142); ImageGeneration.CircularCrop(avatar); image.Composite(avatar, 32, 32, CompositeOperator.Over, Channels.RGB); return(image.ToByteArray(MagickFormat.Png)); }
public static async Task <byte[]> GenerateAsync( string avatarUrl, string username, string discriminator, string level, string reputation, string credits, string rank, string experience, float percentage, string themeColor) { using var avatar = new MagickImage(await ImageGeneration.Client.GetByteArrayAsync(avatarUrl)); using var image = new MagickImage(Template, PixelReadSettings); avatar.Resize(150, 150); ImageGeneration.CircularCrop(avatar); image.Composite(avatar, 45, 45, CompositeOperator.Over, Channels.RGB); var percentagePixels = 501 * percentage; var color = new MagickColor($"#{themeColor}"); var drawables = new Drawables() // Set up the font metadata .FillColor(new MagickColor(51, 51, 51)) .TextAlignment(TextAlignment.Left) // Draw the discriminator .FontPointSize(35) .Font("Roboto", FontStyleType.Normal, FontWeight.Light, FontStretch.Normal) .Text(273, 155, $"#{discriminator}") // Prepare to draw the username .FontPointSize(55); var metric = drawables.FontTypeMetrics(username); if (metric.TextWidth > 385.0) { drawables.FontPointSize(385.0 * 55.0 / metric.TextWidth); } drawables // Draw the username .Font("Roboto", FontStyleType.Normal, FontWeight.Medium, FontStretch.Normal) .Text(273, 107, username) // Draw the level .FontPointSize(60) .TextAlignment(TextAlignment.Center) .Text(724, 163, level) // Draw the reputation, credits, and rank .FontPointSize(32) .Text(344, 305, reputation) .Text(504, 305, credits) .Text(664, 305, rank) // Draw the experience .TextAlignment(TextAlignment.Right) .Text(748, 486, experience) // Draw the experience bar .FillColor(color) .Polygon( new PointD(241, 500), new PointD(241 + percentagePixels, 500), new PointD(241 + percentagePixels + 39, 539), new PointD(280, 539) ) // Draw the results .Draw(image); image.Draw( new DrawableStrokeColor(color), TemplateCircleStrokeWidth, TemplateCircleFillColor, TemplateDrawableCircle ); return(image.ToByteArray(MagickFormat.Png)); }