Beispiel #1
0
        public async Task GetCardAsync(SocketUser user = null)
        {
            user ??= Context.User;
            if (!Context.Container.TryGetUser(user.Id, out User account))
            {
                await Context.Channel.ThrowAsync("The specified user does not have an existing account.");

                return;
            }

            try
            {
                using var graphics = new GraphicsService();
                var d = new CardDetails(account, user);
                var p = CardProperties.Default;

                p.Palette = PaletteType.Glass;
                p.Trim    = false;
                p.Casing  = Casing.Upper;

                Bitmap card = graphics.DrawCard(d, p);

                await Context.Channel.SendImageAsync(card, $"../tmp/{Context.User.Id}_card.png");
            }
            catch (Exception ex)
            {
                await Context.Channel.CatchAsync(ex);
            }
        }
Beispiel #2
0
        public async Task DrawMaskAsync()
        {
            using (var g = new GraphicsService())
            {
                var d = new CardDetails(Context.Account, Context.User);

                using (Bitmap card = g.DrawCard(d, PaletteType.GammaGreen))
                {
                    using (var factory = new TextFactory())
                    {
                        Grid <float> mask = ImageHelper.GetOpacityMask(card);

                        var pixels = new Grid <Color>(card.Size, new ImmutableColor(0, 0, 0, 255));

                        // TODO: Make ImmutableColor.Empty values
                        pixels.SetEachValue((x, y) =>
                                            ImmutableColor.Blend(new ImmutableColor(0, 0, 0, 255), new ImmutableColor(255, 255, 255, 255),
                                                                 mask.GetValue(x, y)));

                        using (Bitmap masked = ImageHelper.CreateRgbBitmap(pixels.Values))
                            await Context.Channel.SendImageAsync(masked, $"../tmp/{Context.User.Id}_card_mask.png");
                    }
                }
            }
        }
Beispiel #3
0
        public async Task GetCardAsync(SocketUser user = null)
        {
            user ??= Context.User;
            Context.TryGetUser(user.Id, out ArcadeUser account);

            if (await CatchEmptyAccountAsync(account))
            {
                return;
            }

            try
            {
                using var graphics = new GraphicsService();
                var d = new CardDetails(account, user);
                var p = CardProperties.Default;
                p.Font            = account.Card.Font;
                p.Palette         = account.Card.Palette.Primary;
                p.PaletteOverride = account.Card.Palette.Build();
                p.Trim            = false;
                p.Casing          = Casing.Upper;

                System.Drawing.Bitmap card = graphics.DrawCard(d, p);

                await Context.Channel.SendImageAsync(card, $"../tmp/{Context.User.Id}_card.png");
            }
            catch (Exception ex)
            {
                await Context.Channel.CatchAsync(ex);
            }
        }
Beispiel #4
0
        public async Task DrawCardMaskAsync()
        {
            using var g = new GraphicsService();
            var d = new CardDetails(Context.Account, Context.User);

            using (Bitmap card = g.DrawCard(d, PaletteType.GammaGreen))
            {
                Grid <float> mask = ImageHelper.GetOpacityMask(card);

                using (Bitmap gradient = ImageHelper.CreateGradient(GammaPalette.GammaGreen, card.Width, card.Height, 0.0f))
                    using (Bitmap result = ImageHelper.SetOpacityMask(gradient, mask))
                        await Context.Channel.SendImageAsync(result, $"../tmp/{Context.User.Id}_gradient_card_mask.png");
            }
        }
Beispiel #5
0
        public async Task GetCardAsync(bool trim, CardDeny deny, BorderAllow border,
                                       Casing casing, FontType font, PaletteType palette, Gamma usernameGamma = Gamma.Max,
                                       Gamma activityGamma = Gamma.Max, Gamma borderGamma = Gamma.Max, ImageScale scale = ImageScale.Medium, int padding = 2)
        {
            SocketUser user = Context.User;

            if (!Context.Container.TryGetUser(user.Id, out User account))
            {
                await Context.Channel.ThrowAsync("The specified user does not have an existing account.");

                return;
            }

            try
            {
                using var graphics = new GraphicsService();
                var d = new CardDetails(account, user);

                var p = new CardProperties
                {
                    Trim    = trim,
                    Deny    = deny,
                    Border  = border,
                    Casing  = casing,
                    Font    = font,
                    Palette = palette,
                    Gamma   = new Dictionary <CardComponentType, Gamma?>
                    {
                        [CardComponentType.Username]   = usernameGamma,
                        [CardComponentType.Activity]   = activityGamma,
                        [CardComponentType.Border]     = borderGamma,
                        [CardComponentType.Background] = null,
                        [CardComponentType.Avatar]     = Gamma.Max
                    },
                    Padding = new Padding(padding),
                    Scale   = scale
                };

                Bitmap card = graphics.DrawCard(d, p);

                Logger.Debug("Drawing card...");
                await Context.Channel.SendImageAsync(card, $"../tmp/{Context.User.Id}_card.png");
            }
            catch (Exception ex)
            {
                await Context.Channel.CatchAsync(ex);
            }
        }