Example #1
0
        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));
        }
        public static MagickImage GetImage()
        {
            if (!IsInitialized)
            {
                return(null);
            }

            var img = new MagickImage(background);

            if (Foreground > 0)
            {
                if (Foreground == 1)
                {
                    img.Composite(circular, CompositeOperator.Over);
                }
                if (Foreground == 2)
                {
                    img.Composite(rectangular, CompositeOperator.Over);
                }
            }

            img.Composite(logo_main, CompositeOperator.Over);
            img.Composite(logo_stripes, CompositeOperator.Over);

            var d = new Drawables();

            d.FontPointSize(FontSize);
            d.Font(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft/Windows/Fonts/SFProDisplay-BlackItalic.ttf"));
            d.TextAlignment(TextAlignment.Center);
            d.TextAntialias(true);
            d.FillColor(new MagickColor("#000F"));
            d.Text(92, 154, Name == "" ? " " : Name);
            d.Text(93, 154, Name == "" ? " " : Name);
            d.Text(94, 154, Name == "" ? " " : Name);
            d.Text(92, 155, Name == "" ? " " : Name);
            d.Text(94, 155, Name == "" ? " " : Name);
            d.Text(92, 156, Name == "" ? " " : Name);
            d.Text(93, 156, Name == "" ? " " : Name);
            d.Text(94, 156, Name == "" ? " " : Name);
            d.FillColor(new MagickColor("#00ADFFFF"));
            d.Text(93, 155, Name == "" ? " " : Name);

            img.Draw(d);

            if (Color != 0)
            {
                if (Color == 1)
                {
                    img.Modulate(new Percentage(100), new Percentage(100), new Percentage((-75 * 100 / 180) + 100));
                }
                if (Color == 2)
                {
                    img.Modulate(new Percentage(100), new Percentage(100), new Percentage((-155 * 100 / 180) + 100));
                }
                if (Color == 3)
                {
                    img.Modulate(new Percentage(100), new Percentage(100), new Percentage((70 * 100 / 180) + 100));
                }
                if (Color == 4)
                {
                    img.Modulate(new Percentage(100), new Percentage(100), new Percentage((-180 * 100 / 180) + 100));
                }
                if (Color == 5)
                {
                    img.Modulate(new Percentage(100), new Percentage(100), new Percentage((140 * 100 / 180) + 100));
                }
            }

            return(img);
        }