Exemple #1
0
        private static void WriteLabelAndBoundingBox(IMagickImage outputImage, int imageHeight, string text, double[] bb, string drawColor)
        {
            DrawableStrokeColor strokeColor = new DrawableStrokeColor(new MagickColor(drawColor));
            DrawableStrokeWidth strokeWidth = new DrawableStrokeWidth(3);
            DrawableFillColor   fillColor   = new DrawableFillColor(new MagickColor(50, 50, 50, 128));
            DrawableRectangle   dr          = new DrawableRectangle(bb[0], bb[1], bb[4], bb[5]);
            DrawableText        dt          = new DrawableText(bb[0], bb[1], text);

            outputImage.Draw(strokeColor, strokeWidth, fillColor, dr, dt);
        }
Exemple #2
0
        public void LineNoize()
        {
            var rnd   = new Random((int)Environment.TickCount);
            var count = rnd.Next(6 * Math.Max(_current.Width, _current.Height));

            for (int i = 0; i < count; i++)
            {
                var    x1  = rnd.Next(0, _current.Width);
                var    y1  = rnd.Next(0, _current.Height);
                var    x2  = rnd.Next(-25, 25);
                var    y2  = rnd.Next(-25, 25);
                byte[] rgb = new byte[3];
                rnd.NextBytes(rgb);
                DrawableFillColor fillColor = new DrawableFillColor(MagickColor.FromRgb(rgb[0], rgb[1], rgb[2]));
                DrawableLine      dl        = new DrawableLine(x1, y1, x1 + x2, y1 + y2);
                _current.Draw(fillColor, dl);
            }
        }
Exemple #3
0
        public static string AddTextToImage(string imageFile, string text)
        {
            var image = new MagickImage(imageFile);

            using (var imgText = new MagickImage())
            {
                var drawable    = new DrawableText(0, 10, text);
                var gravity     = new DrawableGravity(Gravity.North);
                var font        = new DrawableFont("Arial");
                var antialias   = new DrawableTextAntialias(true);
                var size        = new DrawableFontPointSize(50);
                var color       = new DrawableFillColor(Color.Snow);
                var strokeColor = new DrawableStrokeColor(Color.OrangeRed);
                image.Draw(drawable, gravity, font, antialias, size, color, strokeColor);
            }
            // Save the result
            string outputImage = TempFolder + "\\waterMark_" + Path.GetFileName(imageFile);

            image.Write(outputImage);
            return(outputImage);
        }
Exemple #4
0
        public void Stamp(ThumbnailSheetCreateRequest request, string filePath, TimeSpan time)
        {
            var stampText    = time.ToString(request.VideoDurationInSeconds >= 3600 ? @"hh\:mm\:ss" : @"mm\:ss");
            var tempFilePath = filePath + ".tmp.png";

            using (var imgText = new MagickImage(filePath))
            {
                var drawable    = new DrawableText(5, 5, stampText);
                var gravity     = new DrawableGravity(Gravity.Southeast);
                var font        = new DrawableFont("Tahoma");
                var antialias   = new DrawableTextAntialias(true);
                var size        = new DrawableFontPointSize(48);
                var color       = new DrawableFillColor(MagickColors.Black);
                var strokecolor = new DrawableStrokeColor(MagickColors.AliceBlue);
                imgText.Draw(drawable, gravity, font, antialias, size, color, strokecolor);
                imgText.Write(tempFilePath);
            }

            File.Delete(filePath);
            File.Move(tempFilePath, filePath);
        }
Exemple #5
0
        public void Constructor_WithColor_ColorPropertyIsCorrect()
        {
            DrawableFillColor fillColor = new DrawableFillColor(Color.DarkKhaki);

            ColorAssert.AreEqual(MagickColors.DarkKhaki, fillColor.Color);
        }
Exemple #6
0
        public void Test_Constructor_Color()
        {
            DrawableFillColor fillColor = new DrawableFillColor(Color.DarkKhaki);

            ColorAssert.AreEqual(MagickColors.DarkKhaki, fillColor.Color);
        }
Exemple #7
0
        public void Execute()
        {
            MontageConfig montageConfig = Config.Montages;

            if (montageConfig == null)
            {
                throw new ConfigurationException("Montage action performed, but no montages are defined in the configuration.");
            }

            string font = montageConfig.Font ?? DefaultFontFamily();

            MontageSettings montageSettings = new MontageSettings()
            {
                BackgroundColor = MagickColors.None,
                Geometry        = new MagickGeometry(2, 2, 0, 0),
                TileGeometry    = new MagickGeometry(8, 0),
                Font            = font
            };

            MagickReadSettings magickSettings = new MagickReadSettings()
            {
                FontFamily      = font,
                FontPointsize   = 14,
                BackgroundColor = MagickColors.None,
                FillColor       = MagickColors.White
            };

            foreach (PatternConfig pattern in montageConfig.Patterns)
            {
                string              name         = pattern.Name;
                DataResolver        resolver     = new DataResolver(pattern.Source);
                List <ResolvedData> resolverData = resolver.Data;

                if (resolverData.Count == 0)
                {
                    throw new ConfigurationException($"The pattern for montage {name} doesn't match any files, exiting the application.");
                }

                resolverData.Sort();

                using (MagickImageCollection collection = new MagickImageCollection())
                {
                    foreach (ResolvedData resolvedFile in resolverData)
                    {
                        string filename      = resolvedFile.Name;
                        string fileShortName = Path.GetFileNameWithoutExtension(filename);

                        MagickImage magickImage = resolvedFile.ToMagickImage(magickSettings);
                        magickImage.Extent(128, 144, MagickColors.None);

                        MagickColor       color         = MagickColor.FromRgba(0, 0, 0, 88);
                        DrawableRectangle drawableRect  = new DrawableRectangle(0, 128, 144, 144);
                        DrawableFillColor drawableColor = new DrawableFillColor(color);
                        magickImage.Draw(drawableColor, drawableRect);

                        magickImage.Annotate(fileShortName, Gravity.South);

                        collection.Add(magickImage);
                        Logger.Debug("Appended montage {0} with: {1}", name, resolvedFile);
                    }

                    Logger.Debug("Finished collecting input, creating a montage of {0} images.", collection.Count);

                    using (IMagickImage montage = collection.Montage(montageSettings))
                    {
                        string filepath = Path.Combine("build", "montages", name + ".png");

                        FileInfo outputPath = new FileInfo(filepath);
                        outputPath.Directory?.Create();

                        Logger.Debug("Writing monatage with name {0} to {1}.", name, filepath);
                        montage.Write(outputPath);
                    }
                }
            }
        }