Exemplo n.º 1
0
        public void DrawEclipse(PointF position, SizeF size, string color, int penWidth, bool isFill)
        {
            var polygon = ToEllipsePolygon(position, size, world);

            if (isFill)
            {
                commandQueue.Enqueue(ctx =>
                {
                    ctx.Fill(
                        Rgba32.FromHex(color)
                        , polygon
                        , currentOption);
                });
            }
            else
            {
                commandQueue.Enqueue(ctx =>
                {
                    ctx.Draw(
                        Rgba32.FromHex(color)
                        , penWidth
                        , polygon
                        , currentOption);
                });
            }
        }
Exemplo n.º 2
0
        private async Task <Image <Rgba32> > GetSiteStatisticUserBadge(string avatarUrl, string name, string color)
        {
            var font = GetFontSize(_latoBold, 32, name, 360);

            var badge = new Image <Rgba32>(450, 65);

            badge.Mutate(x => x.DrawText(name, font, Rgba32.FromHex("#A4A4A4"), new Point(72, 6 + (int)((58 - font.Size) / 2))));

            using (var border = new Image <Rgba32>(3, 57))
            {
                border.Mutate(x => x.BackgroundColor(Rgba32.FromHex(color)));
                badge.Mutate(x => x.DrawImage(border, new Point(63, 5), 1));
            }

            using (var stream = await GetImageFromUrlAsync(avatarUrl))
            {
                if (stream == null)
                {
                    return(badge);
                }

                using (var avatar = Image.Load(stream))
                {
                    avatar.Mutate(x => x.Resize(new ResizeOptions
                    {
                        Mode = ResizeMode.Crop,
                        Size = new Size(57, 57)
                    }));
                    badge.Mutate(x => x.DrawImage(avatar, new Point(6, 5), 1));
                }
            }

            return(badge);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Add a password to the image.
        /// </summary>
        /// <param name="curImg">Image to add password to.</param>
        /// <param name="pass">Password to add to top left corner.</param>
        /// <returns>Image with the password in the top left corner.</returns>
        private (Stream, string) AddPassword(byte[] curImg, string pass)
        {
            // draw lower, it looks better
            pass = pass.TrimTo(10, true).ToLowerInvariant();
            using (var img = Image.Load(curImg, out var format))
            {
                // choose font size based on the image height, so that it's visible
                var font = _fonts.NotoSans.CreateFont(img.Height / 12, FontStyle.Bold);
                img.Mutate(x =>
                {
                    // measure the size of the text to be drawing
                    var size = TextMeasurer.Measure(pass, new RendererOptions(font, new PointF(0, 0)));

                    // fill the background with black, add 5 pixels on each side to make it look better
                    x.FillPolygon(Rgba32.FromHex("00000080"),
                                  new PointF(0, 0),
                                  new PointF(size.Width + 5, 0),
                                  new PointF(size.Width + 5, size.Height + 10),
                                  new PointF(0, size.Height + 10));

                    // draw the password over the background
                    x.DrawText(pass,
                               font,
                               Brushes.Solid(Rgba32.White),
                               new PointF(0, 0));
                });
                // return image as a stream for easy sending
                return(img.ToStream(format), format.FileExtensions.FirstOrDefault() ?? "png");
            }
        }
Exemplo n.º 4
0
        private void ApplyLambdaStats(Image <Rgba32> image, Card card)
        {
            var aphFont = new Font(_latoBold, 28);

            int hp  = card.GetHealthWithPenalty();
            int def = card.GetDefenceWithBonus();
            int atk = card.GetAttackWithBonus();

            using (var hpImg = new Image <Rgba32>(120, 40))
            {
                hpImg.Mutate(x => x.DrawText($"{hp}", aphFont, Rgba32.FromHex("#6bedc8"), new Point(1)));
                hpImg.Mutate(x => x.Rotate(-19));

                image.Mutate(x => x.DrawImage(hpImg, new Point(57, 555), 1));
            }

            using (var atkImg = new Image <Rgba32>(120, 40))
            {
                atkImg.Mutate(x => x.DrawText($"{atk}", aphFont, Rgba32.FromHex("#fda9fd"), new Point(1)));
                atkImg.Mutate(x => x.Rotate(34));

                image.Mutate(x => x.DrawImage(atkImg, new Point(80, 485), 1));
            }

            image.Mutate(x => x.DrawText($"{def}", aphFont, Rgba32.FromHex("#49deff"), new Point(326, 576)));
        }
Exemplo n.º 5
0
        private Task <string> CreateFallbackAvatar(long id, Size size)
        {
            return(Task.Run(() =>
            {
                var color = _colorMaker.GetHexFromId(id);
                var s = (int)size;

                var avatarFile = GetAvatarFilename(size, color);

                if (!File.Exists(avatarFile))
                {
                    using (var image = new Image <Rgba32>(s, s))
                    {
                        var brush = new SolidBrush <Rgba32>(Rgba32.FromHex(color));
                        var ellipse = new EllipsePolygon(s / 2.0f, s / 2.0f, s, s);
                        var options = new GraphicsOptions(true)
                        {
                            BlenderMode = PixelBlenderMode.Out
                        };

                        image.Mutate(ctx =>
                                     ctx.BackgroundColor(Rgba32.Transparent)
                                     .Fill(options, brush, ellipse));

                        image.Save(avatarFile);
                    }
                }

                return avatarFile;
            }));
        }
Exemplo n.º 6
0
        public Rgba32 GetColour(Point p)
        {
            if (p.escaped)
            {
                double escapePercentage = p.iterations * 1.0 / _maxIterations;

                int r = (int)Math.Abs(redInterpolator.GetYPoint(escapePercentage));
                int g = (int)Math.Abs(greenInterpolator.GetYPoint(escapePercentage));
                int b = (int)Math.Abs(blueInterpolator.GetYPoint(escapePercentage));

                try
                {
                    return(Rgba32.FromHex($"{r:X2}{g:X2}{b:X2}"));
                }
                catch (Exception)
                {
                    Console.WriteLine($"{r}|{g}|{b}");
                    Console.WriteLine($"{r:X2}{g:X2}{b:X2}");
                    throw;
                }
            }
            else
            {
                return(Rgba32.FromHex(_setColour));
            }
        }
Exemplo n.º 7
0
        public async Task Color([Remainder] string color = null)
        {
            color = color?.Trim().Replace("#", "");
            if (string.IsNullOrWhiteSpace(color))
            {
                return;
            }
            Rgba32 clr;

            try
            {
                clr = Rgba32.FromHex(color);
            }
            catch
            {
                await ReplyErrorLocalized("hex_invalid").ConfigureAwait(false);

                return;
            }


            var img = new ImageSharp.Image <Rgba32>(50, 50);

            img.BackgroundColor(clr);

            await Context.Channel.SendFileAsync(img.ToStream(), $"{color}.png").ConfigureAwait(false);
        }
        private void RefreshScreen()
        {
            var pixels = new Image <Rgba32>(DisplayWidth, DisplayHeight);

            var x = 0;
            var y = 0;

            foreach (var pixel in _rgb)
            {
                if (x == DisplayWidth)
                {
                    x = 0;
                    y++;
                }

                var hex = "#" + pixel.ToString("X6");
                pixels[x, y] = Rgba32.FromHex(hex);

                x++;
            }

            byte[] bytes;
            using (var memoryStream = new MemoryStream())
            {
                pixels.SaveAsBmp(memoryStream);
                pixels.Dispose();
                bytes = memoryStream.ToArray();
            }

            OnFrameProduced?.Invoke(this, bytes);

            _i = 0;
        }
Exemplo n.º 9
0
        public async Task Color(params string[] colors)
        {
            if (!colors.Any())
            {
                return;
            }

            var colorObjects = colors.Take(10).Select(x => x.Trim().Replace("#", ""))
                               .Select(x =>
            {
                try
                {
                    return(Rgba32.FromHex(x));
                }
                catch
                {
                    return(Rgba32.FromHex("000"));
                }
            }).ToArray();

            using (var img = new Image <Rgba32>(colorObjects.Length * 50, 50))
            {
                for (int i = 0; i < colorObjects.Length; i++)
                {
                    var x = i * 50;
                    img.FillPolygon(colorObjects[i], new PointF[] {
                        new PointF(x, 0),
                        new PointF(x + 50, 0),
                        new PointF(x + 50, 50),
                        new PointF(x, 50)
                    });
                }
                await Context.Channel.SendFileAsync(img.ToStream(), $"colors.png").ConfigureAwait(false);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 获取泡泡样式验证码
        /// </summary>
        /// <param name="text">2-3个文字,中文效果较好</param>
        /// <param name="width">验证码宽度,默认宽度100px,可根据传入</param>
        /// <param name="format"></param>
        /// <returns>验证码图片字节数组</returns>
        public byte[] GetBubbleCodeByte(string text)
        {
            using (Image <Rgba32> img = new Image <Rgba32>(_imageWidth, _imageHeight))
            {
                Font textFont = _fontArr.FirstOrDefault(c => "STCAIYUN".Equals(c.Name, StringComparison.CurrentCultureIgnoreCase));
                if (textFont == null)
                {
                    textFont = _fontArr[_random.Next(0, _fontArr.Length)];
                }

                var colorCircleHex = _colorHexArr[_random.Next(0, _colorHexArr.Length)];
                var colorTextHex   = colorCircleHex;

                if (_random.Next(0, 6) == 3)
                {
                    colorCircleHex = "#FFFFFF";//白色
                    _circleCount   = (int)(_circleCount * 2.65);
                }

                img.Mutate(ctx => ctx
                           .Fill(Rgba32.White)
                           .DrawingCnText(_imageWidth, _imageHeight, text, Rgba32.FromHex(colorTextHex), textFont)
                           .DrawingCircles(_imageWidth, _imageHeight, _circleCount, _miniCircleR, _maxCircleR, Rgba32.FromHex(colorCircleHex))
                           );

                using (var ms = new MemoryStream())
                {
                    img.Save(ms, PngFormat.Instance);
                    return(ms.ToArray());
                }
            }
        }
Exemplo n.º 11
0
        public IActionResult ProcessImage([FromForm] IFormFile img, [FromForm] IEnumerable <string> colors, [FromForm] bool resize = false)
        {
            if (img == null)
            {
                throw new ArgumentNullException(nameof(img));
            }
            if (!fileOptions.AcceptedMimeTypes.Contains(img.ContentType))
            {
                throw new ArgumentException(
                          $"File is not an accepted type. Expected one of: {string.Join(", ", fileOptions.AcceptedMimeTypes)} but received: {img.ContentType}.");
            }
            if (colors == null)
            {
                throw new ArgumentNullException(nameof(colors));
            }
            if (colors.Count() < 2)
            {
                throw new ArgumentException("Color palette must be at least two colors.", nameof(colors));
            }

            var palette = colors.Select(c => Rgba32.FromHex(c));

            using var sourceImage = Image.Load(img.OpenReadStream());
            if (resize || img.Length > fileOptions.MaxSizeInBytesBeforeResizing)
            {
                resizer.Resize(sourceImage, GameBoyConstants.ScreenWidth, GameBoyConstants.ScreenHeight);
            }
            using var outputImage = converter.Convert(sourceImage, palette);
            return(File(converter.ToBytes(outputImage), "image/png"));
        }
Exemplo n.º 12
0
        public static void SaveLogo(float size, string path)
        {
            // the point are based on a 1206x1206 shape so size requires scaling from there

            float scalingFactor = size / 1206;

            Vector2 center = new Vector2(603);

            // segment whoes cetner of rotation should be
            Vector2 segmentOffset = new Vector2(301.16968f, 301.16974f);
            IPath   segment       = new Polygon(new LinearLineSegment(new Vector2(230.54f, 361.0261f), new System.Numerics.Vector2(5.8641942f, 361.46031f)),
                                                new CubicBezierLineSegment(new Vector2(5.8641942f, 361.46031f),
                                                                           new Vector2(-11.715693f, 259.54052f),
                                                                           new Vector2(24.441609f, 158.17478f),
                                                                           new Vector2(78.26f, 97.0461f))).Translate(center - segmentOffset);


            //we need to create 6 of theses all rotated about the center point
            List <IPath> segments = new List <IPath>();

            for (int i = 0; i < 6; i++)
            {
                float angle = i * ((float)Math.PI / 3);
                IPath s     = segment.Transform(Matrix3x2.CreateRotation(angle, center));
                segments.Add(s);
            }

            List <Rgba32> colors = new List <Rgba32>()
            {
                Rgba32.FromHex("35a849"),
                Rgba32.FromHex("fcee21"),
                Rgba32.FromHex("ed7124"),
                Rgba32.FromHex("cb202d"),
                Rgba32.FromHex("5f2c83"),
                Rgba32.FromHex("085ba7"),
            };

            Matrix3x2 scaler = Matrix3x2.CreateScale(scalingFactor, Vector2.Zero);

            int dimensions = (int)Math.Ceiling(size);

            using (Image <Rgba32> img = new Image <Rgba32>(dimensions, dimensions))
            {
                img.Mutate(i => i.Fill(Rgba32.Black));
                img.Mutate(i => i.Fill(Rgba32.FromHex("e1e1e1ff"), new EllipsePolygon(center, 600f).Transform(scaler)));
                img.Mutate(i => i.Fill(Rgba32.White, new EllipsePolygon(center, 600f - 60).Transform(scaler)));

                for (int s = 0; s < 6; s++)
                {
                    img.Mutate(i => i.Fill(colors[s], segments[s].Transform(scaler)));
                }

                img.Mutate(i => i.Fill(new Rgba32(0, 0, 0, 170), new ComplexPolygon(new EllipsePolygon(center, 161f), new EllipsePolygon(center, 61f)).Transform(scaler)));

                string fullPath = System.IO.Path.GetFullPath(System.IO.Path.Combine("Output", path));

                img.Save(fullPath);
            }
        }
Exemplo n.º 13
0
        public async Task <Image <Rgba32> > GetLevelUpBadgeAsync(string name, long ulvl, string avatarUrl, Discord.Color color)
        {
            if (color == Discord.Color.Default)
            {
                color = Discord.Color.DarkerGrey;
            }

            var msgText1 = "POZIOM";
            var msgText2 = "Awansuje na:";

            var textFont     = new Font(_latoRegular, 16);
            var nickNameFont = new Font(_latoBold, 22);
            var lvlFont      = new Font(_latoBold, 36);

            var msgText1Length = TextMeasurer.Measure(msgText1, new RendererOptions(textFont));
            var msgText2Length = TextMeasurer.Measure(msgText2, new RendererOptions(textFont));
            var nameLength     = TextMeasurer.Measure(name, new RendererOptions(nickNameFont));
            var lvlLength      = TextMeasurer.Measure($"{ulvl}", new RendererOptions(lvlFont));

            var textLength      = lvlLength.Width + msgText1Length.Width > nameLength.Width ? lvlLength.Width + msgText1Length.Width : nameLength.Width;
            var estimatedLength = 106 + (int)(textLength > msgText2Length.Width ? textLength : msgText2Length.Width);

            var nickNameColor = color.RawValue.ToString("X6");
            var baseImg       = new Image <Rgba32>((int)estimatedLength, 100);

            baseImg.Mutate(x => x.BackgroundColor(Rgba32.FromHex("#36393e")));
            baseImg.Mutate(x => x.DrawText(msgText1, textFont, Rgba32.Gray, new Point(98 + (int)lvlLength.Width, 75)));
            baseImg.Mutate(x => x.DrawText(name, nickNameFont, Rgba32.FromHex(nickNameColor), new Point(98, 10)));
            baseImg.Mutate(x => x.DrawText(msgText2, textFont, Rgba32.Gray, new Point(98, 33)));
            baseImg.Mutate(x => x.DrawText($"{ulvl}", lvlFont, Rgba32.Gray, new Point(96, 61)));

            using (var colorRec = new Image <Rgba32>(82, 82))
            {
                colorRec.Mutate(x => x.BackgroundColor(Rgba32.FromHex(nickNameColor)));
                baseImg.Mutate(x => x.DrawImage(colorRec, new Point(9, 9), 1));

                using (var stream = await GetImageFromUrlAsync(avatarUrl))
                {
                    if (stream == null)
                    {
                        return(baseImg);
                    }

                    using (var avatar = Image.Load(stream))
                    {
                        avatar.Mutate(x => x.Resize(new ResizeOptions
                        {
                            Mode = ResizeMode.Crop,
                            Size = new Size(80, 80)
                        }));
                        baseImg.Mutate(x => x.DrawImage(avatar, new Point(10, 10), 1));
                    }
                }
            }

            return(baseImg);
        }
Exemplo n.º 14
0
        public void DrawText(PointF position, string text, Font font, string color, int penWidth)
        {
            var p = ToPointF(position, world);

            commandQueue.Enqueue(ctx =>
            {
                ctx.DrawText(text, fontCollection.CreateFont(font.Name, font.Size), Rgba32.FromHex(color), p, currentOption);
            });
        }
Exemplo n.º 15
0
        public void Fill(string color, RectangleF region)
        {
            var r = ToRectangleF(region, world);

            commandQueue.Enqueue(ctx =>
            {
                ctx.Fill(Rgba32.FromHex(color), r);
            });
        }
Exemplo n.º 16
0
        public void Color_Types_From_Hex_Produce_Equal_Scaled_Component_OutPut()
        {
            Rgba32     color       = Rgba32.FromHex("183060C0");
            RgbaVector colorVector = RgbaVector.FromHex("183060C0");

            Assert.Equal(color.R, (byte)(colorVector.R * 255));
            Assert.Equal(color.G, (byte)(colorVector.G * 255));
            Assert.Equal(color.B, (byte)(colorVector.B * 255));
            Assert.Equal(color.A, (byte)(colorVector.A * 255));
        }
Exemplo n.º 17
0
 /// <summary>
 /// Creates an <see cref="AvatarColor"/> based on hex color strings for background and foreground.
 /// </summary>
 /// <param name="background">The background color.</param>
 /// <param name="color">The foreground color.</param>
 public AvatarColor(string background, string color = null)
 {
     Background = Rgba32.FromHex(background);
     if (!string.IsNullOrWhiteSpace(color))
     {
         Color = Rgba32.FromHex(color);
     }
     else
     {
         Color = PerceivedBrightness(Background) > 130 ? Rgba32.Black : Rgba32.White;
     }
 }
Exemplo n.º 18
0
        public static void ApplyBackground(this Image image, string hexColor)
        {
            if (string.IsNullOrWhiteSpace(hexColor))
            {
                hexColor = Constants.DefaultBackgroundColor;
            }

            image.Mutate(c =>
            {
                c.BackgroundColor(Rgba32.FromHex(hexColor));
            });
        }
Exemplo n.º 19
0
        public void AreNotEqual()
        {
            Rgba32 color1 = new Rgba32(255, 0, 0, 255);
            Rgba32 color2 = new Rgba32(0, 0, 0, 255);
            Rgba32 color3 = Rgba32.FromHex("#000");
            Rgba32 color4 = Rgba32.FromHex("#000000");
            Rgba32 color5 = Rgba32.FromHex("#FF000000");

            Assert.NotEqual(color1, color2);
            Assert.NotEqual(color1, color3);
            Assert.NotEqual(color1, color4);
            Assert.NotEqual(color1, color5);
        }
Exemplo n.º 20
0
        private void ApplyGammaStats(Image <Rgba32> image, Card card)
        {
            var aphFont = new Font(_latoBold, 37);

            int hp  = card.GetHealthWithPenalty();
            int def = card.GetDefenceWithBonus();
            int atk = card.GetAttackWithBonus();

            // TODO: center numbers
            image.Mutate(x => x.DrawText($"{atk}", aphFont, Rgba32.FromHex("#a90079"), new Point(196, 495)));
            image.Mutate(x => x.DrawText($"{def}", aphFont, Rgba32.FromHex("#19615e"), new Point(282, 545)));
            image.Mutate(x => x.DrawText($"{hp}", aphFont, Rgba32.FromHex("#318b19"), new Point(90, 545)));
        }
Exemplo n.º 21
0
        /// <inheritdoc/>
        public override object ConvertFrom(CultureInfo culture, string value, Type propertyType)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return(base.ConvertFrom(culture, value, propertyType));
            }

            // Special case. HTML requires LightGrey, but NamedColors has LightGray to conform with System.Drawing
            // Check early on.
            if (value.Equals("LightGrey", StringComparison.OrdinalIgnoreCase))
            {
                return(Rgba32.LightGray);
            }

            // Numeric r,g,b - r,g,b,a
            char separator = culture.TextInfo.ListSeparator[0];

            if (value.Contains(separator.ToString()))
            {
                string[] components = value.Split(separator);

                bool convert = true;
                foreach (string component in components)
                {
                    if (!NumberRegex.IsMatch(component))
                    {
                        convert = false;
                    }
                }

                if (convert)
                {
                    List <byte> rgba = CommandParser.Instance.ParseValue <List <byte> >(value);

                    return(rgba.Count == 4
                        ? ColorBuilder <Rgba32> .FromRGBA(rgba[0], rgba[1], rgba[2], rgba[3])
                        : ColorBuilder <Rgba32> .FromRGB(rgba[0], rgba[1], rgba[2]));
                }
            }

            // Hex colors rgb, rrggbb, rrggbbaa
            if (HexColorRegex.IsMatch(value))
            {
                return(Rgba32.FromHex(value));
            }

            // Named colors
            IDictionary <string, Rgba32> table = ColorConstantsTable.Value;

            return(table.ContainsKey(value) ? table[value] : base.ConvertFrom(culture, value, propertyType));
        }
        private static Image <Rgba32> CreateProfileImage(Image photoOfFaceWithoutBackground)
        {
            var profileImage = new Image <Rgba32>(512, 512);

            profileImage.Mutate(ctx =>
            {
                ctx.BackgroundColor(Rgba32.FromHex(BackgroundColor));
                ctx.ApplyFrame();
                ctx.ApplyPhoto(photoOfFaceWithoutBackground);
                ctx.ApplyRoundedCorners(256);
            });

            return(profileImage);
        }
Exemplo n.º 23
0
        //Draw
        private static async Task Draw(ulong id)
        {
            using (var stream = new MemoryStream())
                using (var image = Image.Load(outputArray))
                {
                    PointF Point1  = new PointF(50, 60);
                    var    thefont = new Font(font, 120 * fontMultiplier);
                    image.Mutate(x => x.DrawText("Level Up", thefont, Rgba32.FromHex(hex), Point1));

                    image.SaveAsGif(stream);
                    outputArray = stream.ToArray();
                }
            await Task.CompletedTask;
        }
Exemplo n.º 24
0
        public async Task <Image <Rgba32> > GetSiteStatisticAsync(IUserInfo shindenInfo, Discord.Color color, List <ILastReaded> lastRead = null, List <ILastWatched> lastWatch = null)
        {
            if (color == Discord.Color.Default)
            {
                color = Discord.Color.DarkerGrey;
            }

            var baseImg = new Image <Rgba32>(500, 320);

            baseImg.Mutate(x => x.BackgroundColor(Rgba32.FromHex("#36393e")));

            using (var template = Image.Load("./Pictures/siteStatsBody.png"))
            {
                baseImg.Mutate(x => x.DrawImage(template, new Point(0, 0), 1));
            }

            using (var avatar = await GetSiteStatisticUserBadge(shindenInfo.AvatarUrl, shindenInfo.Name, color.RawValue.ToString("X6")))
            {
                baseImg.Mutate(x => x.DrawImage(avatar, new Point(0, 0), 1));
            }

            using (var image = new Image <Rgba32>(325, 248))
            {
                if (shindenInfo?.ListStats?.AnimeStatus != null)
                {
                    using (var stats = GetRWStats(shindenInfo?.ListStats?.AnimeStatus,
                                                  "./Pictures/statsAnime.png", shindenInfo.GetMoreSeriesStats(false)))
                    {
                        image.Mutate(x => x.DrawImage(stats, new Point(0, 0), 1));
                    }
                }
                if (shindenInfo?.ListStats?.MangaStatus != null)
                {
                    using (var stats = GetRWStats(shindenInfo?.ListStats?.MangaStatus,
                                                  "./Pictures/statsManga.png", shindenInfo.GetMoreSeriesStats(true)))
                    {
                        image.Mutate(x => x.DrawImage(stats, new Point(0, 128), 1));
                    }
                }
                baseImg.Mutate(x => x.DrawImage(image, new Point(5, 71), 1));
            }

            using (var image = await GetLastRWList(lastRead, lastWatch))
            {
                baseImg.Mutate(x => x.DrawImage(image, new Point(330, 69), 1));
            }

            return(baseImg);
        }
Exemplo n.º 25
0
        public void AreEqual()
        {
            Rgba32 color1 = new Rgba32(0, 0, 0);
            Rgba32 color2 = new Rgba32(0, 0, 0, 1F);
            Rgba32 color3 = Rgba32.FromHex("#000");
            Rgba32 color4 = Rgba32.FromHex("#000F");
            Rgba32 color5 = Rgba32.FromHex("#000000");
            Rgba32 color6 = Rgba32.FromHex("#000000FF");

            Assert.Equal(color1, color2);
            Assert.Equal(color1, color3);
            Assert.Equal(color1, color4);
            Assert.Equal(color1, color5);
            Assert.Equal(color1, color6);
        }
Exemplo n.º 26
0
        public static async Task WriteText(FontFamily fam)
        {
            MemoryStream output = new MemoryStream();

            using (var overlay = Image.Load($"{Program.Rootdir}\\Config\\Sample.png"))
            {
                PointF Point1 = new PointF(10, 10);
                Font   font2  = new Font(fam, 72 * fontMultiplier);
                overlay.Mutate(x => x
                               .DrawText("Sample Text", font2, Rgba32.FromHex("#000000"), Point1)
                               );
                overlay.SaveAsPng(output);
                await File.WriteAllBytesAsync($"{Program.Rootdir}\\Resources\\Fonts\\{fam.Name}.png", output.ToArray());
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// 生成一个数组组合验证码素材(Image)
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        private Image <Rgba32> getEnDigitalCodeImage(string text)
        {
            Image <Rgba32> img            = new Image <Rgba32>(_imageWidth, _imageHeight);
            var            colorTextHex   = _colorHexArr[_random.Next(0, _colorHexArr.Length)];
            var            lignthColorHex = _lightColorHexArr[_random.Next(0, _lightColorHexArr.Length)];

            img.Mutate(ctx => ctx
                       .Fill(Rgba32.FromHex(_lightColorHexArr[_random.Next(0, _lightColorHexArr.Length)]))
                       .Glow(Rgba32.FromHex(lignthColorHex))
                       .DrawingGrid(_imageWidth, _imageHeight, Rgba32.FromHex(lignthColorHex), 8, 1)
                       .DrawingEnText(_imageWidth, _imageHeight, text, _colorHexArr, _fontArr)
                       .GaussianBlur(0.4f)
                       .DrawingCircles(_imageWidth, _imageHeight, 15, _miniCircleR, _maxCircleR, Rgba32.White)
                       );
            return(img);
        }
Exemplo n.º 28
0
        public static void OutDataimage(ShowDataList ReadShow, Dictionary <string, TwitterData> ReadData)
        {
            var install_Family = new FontCollection().Install("SourceHanSansCN.ttf");
            var SuiYingfont    = new Font(install_Family, 55); //字体
            var Tetitfont      = new Font(install_Family, 40); //字体
            var Strfont        = new Font(install_Family, 35); //字体

            foreach (var Temp_Show in ReadShow.m_showlist)
            {
                int White     = 750;
                int DelWhite  = 240;
                int imageHead = ((73 + 20) + (60 * Temp_Show.Value.m_screen_name.Count));
                int TilteLend = (GetChineseWord(Temp_Show.Key).Length * 40) + (GetEnglishWord(Temp_Show.Key).Length * 23);
                using (Image <Rgba32> image = new Image <Rgba32>(White, imageHead))
                {
                    int AddTextLine = 80;
                    image.Mutate(x => x.BackgroundColor(Color.White));
                    image.Mutate(x => x.DrawText("今日" + Temp_Show.Value.m_name + "推特趋势", Tetitfont, Rgba32.Black, new Vector2(((White - TilteLend) - DelWhite) / 2, 20)));
                    image.Mutate(x => x.DrawText("八兆木悟志出品", SuiYingfont, Rgba32.FromHex("00000042"), new Vector2(195, imageHead / 2 - 25)));
                    foreach (var Temp in PaiMingYagoo(Temp_Show.Value.m_screen_name))
                    {
                        int    OutData = ReadData[Temp].m_now24 - ReadData[Temp].m_old24;
                        string OutText = GetChineseWord(ReadData[Temp].m_name).Replace("公", "").Replace("発", "").Replace("売", "").Replace("運", "").Replace("堀", "").Replace("中", "");
                        if (OutText.Length > 0)
                        {
                            OutText = OutText + ":" + ReadData[Temp].m_now24;
                        }
                        else
                        {
                            OutText = GetEnglishWord2(ReadData[Temp].m_name).Replace("MotoakiTanigo", "") + ":" + ReadData[Temp].m_now24;
                        }
                        image.Mutate(x => x.DrawText(OutText, Strfont, Rgba32.Black, new Vector2(45, AddTextLine)));
                        if (OutData > 0)
                        {
                            image.Mutate(x => x.DrawText("↑ +" + OutData.ToString(), Strfont, Rgba32.FromHex("4cd01e"), new Vector2(500, AddTextLine)));
                        }
                        else
                        {
                            image.Mutate(x => x.DrawText("↓  " + OutData.ToString(), Strfont, Rgba32.FromHex("e20000"), new Vector2(500, AddTextLine)));
                        }
                        AddTextLine += 60;
                    }
                    image.Save("/usr/share/nginx/html/data/" + Temp_Show.Value.m_name + ".png");
                }
            }
        }
Exemplo n.º 29
0
        public Image <Rgba32> GetDuelCardImage(DuelInfo info, DuelImage image, Image <Rgba32> win, Image <Rgba32> los)
        {
            int Xiw = 76;
            int Yt  = 780;
            int Yi  = 131;
            int Xil = 876;

            if (info.Side == DuelInfo.WinnerSide.Right)
            {
                Xiw = 876;
                Xil = 76;
            }

            var nameFont = new Font(_latoBold, 34);
            var img      = (image != null) ? Image.Load(image.Uri((int)info.Side)) : Image.Load((DuelImage.DefaultUri((int)info.Side)));

            win.Mutate(x => x.Resize(new ResizeOptions
            {
                Mode = ResizeMode.Max,
                Size = new Size(450, 0)
            }));

            los.Mutate(x => x.Resize(new ResizeOptions
            {
                Mode = ResizeMode.Max,
                Size = new Size(450, 0)
            }));

            if (info.Side != DuelInfo.WinnerSide.Draw)
            {
                los.Mutate(x => x.Grayscale());
            }

            img.Mutate(x => x.DrawImage(win, new Point(Xiw, Yi), 1));
            img.Mutate(x => x.DrawImage(los, new Point(Xil, Yi), 1));

            var options = new TextGraphicsOptions()
            {
                HorizontalAlignment = HorizontalAlignment.Center, WrapTextWidth = win.Width
            };

            img.Mutate(x => x.DrawText(options, info.Winner.Name, nameFont, Rgba32.FromHex(image != null ? image.Color : DuelImage.DefaultColor()), new Point(Xiw, Yt)));
            img.Mutate(x => x.DrawText(options, info.Loser.Name, nameFont, Rgba32.FromHex(image != null ? image.Color : DuelImage.DefaultColor()), new Point(Xil, Yt)));

            return(img);
        }
Exemplo n.º 30
0
        private void ApplyZetaStats(Image <Rgba32> image, Card card)
        {
            var aphFont = new Font(_digital, 28);

            int hp  = card.GetHealthWithPenalty();
            int def = card.GetDefenceWithBonus();
            int atk = card.GetAttackWithBonus();

            var ops = new TextGraphicsOptions()
            {
                ApplyKerning = true, DpiX = 80
            };

            image.Mutate(x => x.DrawText(ops, atk.ToString("D4"), aphFont, Rgba32.FromHex("#da4e00"), new Point(316, 538)));
            image.Mutate(x => x.DrawText(ops, def.ToString("D4"), aphFont, Rgba32.FromHex("#00a4ff"), new Point(316, 565)));
            image.Mutate(x => x.DrawText(ops, hp.ToString("D5"), aphFont, Rgba32.FromHex("#40ff40"), new Point(302, 593)));
        }