Exemplo n.º 1
0
 public static void ReadWriteEvents()
 {
   // Load crop script
   MagickScript script = new MagickScript(SampleFiles.CropMsl);
   // Event that will be raised when the script wants to read a file
   script.Read += OnScriptRead;
   // Event that will be raised when the script wants to write a file
   script.Write += OnScriptWrite;
   // Execute the script
   script.Execute();
 }
Exemplo n.º 2
0
        public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
        {
            var conf = new ScriptTransformViewModel(configData);
            using (Stream stream = ToStream(conf.Script))
            {
                MagickScript script = new MagickScript(stream);

                // Read image from file
                using (MagickImage image = new MagickImage(infile))
                {
                    // Execute script with the image and write it to a jpg file
                    script.Execute(image);
                    image.Write(dest);
                }
            }
            return dest;
        }
Exemplo n.º 3
0
    public static void ReuseSameScript()
    {
      // Load wave script
      MagickScript script = new MagickScript(SampleFiles.WaveMsl);

      // Execute script multiple times
      string[] files = new string[] { SampleFiles.FujiFilmFinePixS1ProJpg, SampleFiles.SnakewareJpg };
      foreach (string fileName in files)
      {
        // Read image from file
        using (MagickImage image = new MagickImage(fileName))
        {
          // Execute script with the image and write it to a jpg file
          script.Execute(image);
          image.Write(SampleFiles.OutputDirectory + fileName + ".wave.jpg");
        }
      }
    }
Exemplo n.º 4
0
    public void Test_Execute_Variables()
    {
      MagickScript script = new MagickScript(Files.Scripts.Variables);
      string[] names = script.Variables.Names.ToArray();
      Assert.AreEqual(3, names.Length);
      Assert.AreEqual("width", names[0]);
      Assert.AreEqual("height", names[1]);
      Assert.AreEqual("color", names[2]);

      using (MagickImage image = new MagickImage(Files.MagickNETIconPNG))
      {
        ExceptionAssert.Throws<ArgumentNullException>(delegate ()
        {
          script.Execute(image);
        });

        script.Variables["width"] = "test";

        ExceptionAssert.Throws<FormatException>(delegate ()
        {
          script.Execute(image);
        });

        script.Variables.Set("width", 100);

        ExceptionAssert.Throws<ArgumentNullException>(delegate ()
        {
          script.Execute(image);
        });

        script.Variables["height"] = "100";
        Assert.AreEqual("100", script.Variables.Get("height"));
        script.Variables["color"] = Color.Yellow;

        script.Execute(image);

        Assert.AreEqual(100, image.Width);
        Assert.AreEqual(100, image.Height);
        using (PixelCollection pixels = image.GetReadOnlyPixels())
        {
          ColorAssert.AreEqual(Color.Yellow, pixels.GetPixel(0, 0));
        }
      }
    }
Exemplo n.º 5
0
    public void Test_Execute_Resize()
    {
      MagickScript script = new MagickScript(Files.Scripts.Resize);

      using (MagickImage image = new MagickImage(Files.ImageMagickJPG))
      {
        script.Execute(image);
        TestScriptResizeResult(image);

        script.Read += ResizeScriptRead;
        using (MagickImage result = script.Execute())
        {
          TestScriptResizeResult(result);
        }
      }
    }
Exemplo n.º 6
0
    public void Test_Execute_ImageProfile()
    {
      MagickScript script = new MagickScript(Files.Scripts.ImageProfile);

      using (MagickImage image = new MagickImage(Files.MagickNETIconPNG))
      {
        ColorProfile colorProfile = image.GetColorProfile();
        Assert.IsNull(colorProfile);

        script.Execute(image);

        colorProfile = image.GetColorProfile();

        Assert.IsNotNull(colorProfile);
        Assert.AreEqual(colorProfile.ToByteArray().Length, ColorProfile.SRGB.ToByteArray().Length);
      }
    }
Exemplo n.º 7
0
    public void Test_Execute_Events()
    {
      MagickScript script = new MagickScript(Files.Scripts.Events);

      ExceptionAssert.Throws<InvalidOperationException>(delegate ()
      {
        script.Execute();
      });

      script.Read += Script_ReadNothing;
      ExceptionAssert.Throws<InvalidOperationException>(delegate ()
      {
        script.Execute();
      });
      script.Read -= Script_ReadNothing;

      ExceptionAssert.Throws<InvalidOperationException>(delegate ()
      {
        script.Read += EventsScriptRead;
        script.Read -= EventsScriptRead;
        script.Execute();
      });

      script.Read += EventsScriptRead;

      ExceptionAssert.Throws<InvalidOperationException>(delegate ()
      {
        script.Execute();
      });

      ExceptionAssert.Throws<InvalidOperationException>(delegate ()
      {
        script.Write += EventsScriptWrite;
        script.Write -= EventsScriptWrite;
        script.Execute();
      });

      script.Write += EventsScriptWrite;
      script.Execute();
    }
Exemplo n.º 8
0
    public void Test_Execute_Draw()
    {
      XmlDocument doc = new XmlDocument();
      doc.Load(Files.Scripts.Draw);

      MagickScript script = new MagickScript(doc);

      using (MagickImage image = new MagickImage(Files.ImageMagickJPG))
      {
        script.Execute(image);
      }
    }
Exemplo n.º 9
0
    public void Test_Execute_Distort()
    {
      MagickScript script = new MagickScript(Files.Scripts.Distort);
      MagickImage image = script.Execute();

      Assert.IsNotNull(image);
      Assert.AreEqual(500, image.Width);
      Assert.AreEqual(500, image.Height);
    }
Exemplo n.º 10
0
    public void Test_Execute_Defines()
    {
      MagickScript script = new MagickScript(Files.Scripts.Defines);
      script.Read += DefinesScriptRead;

      MagickImage image = script.Execute();

      Assert.IsNotNull(image);
      Assert.AreEqual(827, image.Width);
      Assert.AreEqual(700, image.Height);
    }
Exemplo n.º 11
0
    public void Test_Execute_Collection()
    {
      MagickScript script = new MagickScript(Files.Scripts.Collection);
      script.Read += CollectionScriptRead;

      MagickImage image = script.Execute();

      Assert.IsNotNull(image);
      Assert.AreEqual(MagickFormat.Png, image.Format);
      Assert.AreEqual(128, image.Width);
      Assert.AreEqual(128, image.Height);
    }
Exemplo n.º 12
0
 public static void WriteMultipleOutputFiles()
 {
   // Load clone script and execute it
   MagickScript script = new MagickScript(SampleFiles.CloneMsl);
   script.Execute();
 }
Exemplo n.º 13
0
 public static void Resize()
 {
   // Load resize script and execute it
   MagickScript script = new MagickScript(SampleFiles.ResizeMsl);
   script.Execute();
 }
Exemplo n.º 14
0
    public void Test_Execute_Variables()
    {
      MagickScript script = new MagickScript(Files.Scripts.Variables);
      string[] names = script.Variables.Names.ToArray();
      Assert.AreEqual(4, names.Length);
      Assert.AreEqual("width", names[0]);
      Assert.AreEqual("height", names[1]);
      Assert.AreEqual("color", names[2]);
      Assert.AreEqual("fillColor", names[3]);

      using (MagickImage image = new MagickImage(Files.MagickNETIconPNG))
      {
        ExceptionAssert.Throws<ArgumentNullException>(delegate ()
        {
          script.Execute(image);
        });

        script.Variables["width"] = "test";

        ExceptionAssert.Throws<FormatException>(delegate ()
        {
          script.Execute(image);
        });

        script.Variables.Set("width", 100);

        ExceptionAssert.Throws<ArgumentNullException>(delegate ()
        {
          script.Execute(image);
        });

        script.Variables["height"] = "100";
        Assert.AreEqual("100", script.Variables.Get("height"));
        script.Variables["color"] = MagickColors.Yellow;
        script.Variables["fillColor"] = MagickColors.Red;

        script.Execute(image);

        Assert.AreEqual(100, image.Width);
        Assert.AreEqual(100, image.Height);
        ColorAssert.AreEqual(MagickColors.Yellow, image, 0, 0);

        ColorAssert.AreEqual(MagickColors.Yellow, image.Settings.StrokeColor);
        ColorAssert.AreEqual(MagickColors.Red, image.Settings.FillColor);
      }
    }
Exemplo n.º 15
0
    public void Test_Execute_Draw()
    {
      XmlDocument doc = new XmlDocument();
      using (FileStream stream = File.OpenRead(Files.Scripts.Draw))
      {
        doc.Load(stream);
      }

      MagickScript script = new MagickScript(doc.CreateNavigator());

      using (MagickImage image = new MagickImage(Files.ImageMagickJPG))
      {
        script.Execute(image);
      }
    }