diff --git a/src/ImageProcessor.Web.UnitTests/RegularExpressionUnitTests.cs b/src/ImageProcessor.Web.UnitTests/RegularExpressionUnitTests.cs
index db81f4533..781cd89f6 100644
--- a/src/ImageProcessor.Web.UnitTests/RegularExpressionUnitTests.cs
+++ b/src/ImageProcessor.Web.UnitTests/RegularExpressionUnitTests.cs
@@ -102,32 +102,6 @@ namespace ImageProcessor.Web.UnitTests
Assert.AreEqual(expected, result);
}
- ///
- /// The saturation regex unit test.
- ///
- ///
- /// The input string.
- ///
- ///
- /// The expected result.
- ///
- [Test]
- [TestCase("saturation=56", 56)]
- [TestCase("saturation=84", 84)]
- [TestCase("saturation=66", 66)]
- [TestCase("saturation=101", 1)]
- [TestCase("saturation=00001", 1)]
- [TestCase("saturation=-50", -50)]
- [TestCase("saturation=0", 0)]
- public void TestSaturationRegex(string input, int expected)
- {
- Processors.Saturation saturation = new Processors.Saturation();
- saturation.MatchRegexIndex(input);
- int result = saturation.Processor.DynamicParameter;
-
- Assert.AreEqual(expected, result);
- }
-
///
/// The rotate regex unit test.
///
@@ -246,21 +220,53 @@ namespace ImageProcessor.Web.UnitTests
Assert.AreEqual(expected, result);
}
+ ///
+ /// The meta regex unit test.
+ ///
+ ///
+ /// The input.
+ ///
+ ///
+ /// The expected result.
+ ///
+ [Test]
+ [TestCase("meta=true", true)]
+ [TestCase("meta=false", false)]
+ public void TestMetaRegex(string input, bool expected)
+ {
+ Processors.Meta meta = new Processors.Meta();
+ meta.MatchRegexIndex(input);
+ bool result = meta.Processor.DynamicParameter;
+
+ Assert.AreEqual(expected, result);
+ }
+
///
/// The resize regex unit test.
///
[Test]
public void TestResizeRegex()
{
- const string Querystring = "width=300";
- ResizeLayer expected = new ResizeLayer(new Size(300, 0));
+ Dictionary data = new Dictionary
+ {
+ {
+ "width=300", new ResizeLayer(new Size(300, 0))
+ },
+ {
+ "height=300", new ResizeLayer(new Size(0, 300))
+ },
+ {
+ "height=300&mode=crop", new ResizeLayer(new Size(0, 300), ResizeMode.Crop)
+ }
+ };
Processors.Resize resize = new Processors.Resize();
-
- resize.MatchRegexIndex(Querystring);
- ResizeLayer actual = resize.Processor.DynamicParameter;
-
- Assert.AreEqual(expected, actual);
+ foreach (KeyValuePair item in data)
+ {
+ resize.MatchRegexIndex(item.Key);
+ ResizeLayer result = resize.Processor.DynamicParameter;
+ Assert.AreEqual(item.Value, result);
+ }
}
///
@@ -315,6 +321,32 @@ namespace ImageProcessor.Web.UnitTests
}
}
+ ///
+ /// The saturation regex unit test.
+ ///
+ ///
+ /// The input string.
+ ///
+ ///
+ /// The expected result.
+ ///
+ [Test]
+ [TestCase("saturation=56", 56)]
+ [TestCase("saturation=84", 84)]
+ [TestCase("saturation=66", 66)]
+ [TestCase("saturation=101", 1)]
+ [TestCase("saturation=00001", 1)]
+ [TestCase("saturation=-50", -50)]
+ [TestCase("saturation=0", 0)]
+ public void TestSaturationRegex(string input, int expected)
+ {
+ Processors.Saturation saturation = new Processors.Saturation();
+ saturation.MatchRegexIndex(input);
+ int result = saturation.Processor.DynamicParameter;
+
+ Assert.AreEqual(expected, result);
+ }
+
///
/// The tint regex unit test.
///
@@ -345,5 +377,42 @@ namespace ImageProcessor.Web.UnitTests
Assert.AreEqual(item.Value, result);
}
}
+
+ ///
+ /// The vignette regex unit test.
+ ///
+ [Test]
+ public void TestVignetteRegex()
+ {
+ Dictionary data = new Dictionary
+ {
+ {
+ "vignette", Color.Black
+ },
+ {
+ "vignette=true", Color.Black
+ },
+ {
+ "vignette=6aa6cc", ColorTranslator.FromHtml("#" + "6aa6cc")
+ },
+ {
+ "vignette=106,166,204,255", Color.FromArgb(255, 106, 166, 204)
+ },
+ {
+ "vignette=fff", Color.FromArgb(255, 255, 255, 255)
+ },
+ {
+ "vignette=white", Color.White
+ }
+ };
+
+ Processors.Vignette vignette = new Processors.Vignette();
+ foreach (KeyValuePair item in data)
+ {
+ vignette.MatchRegexIndex(item.Key);
+ Color result = vignette.Processor.DynamicParameter;
+ Assert.AreEqual(item.Value, result);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/ImageProcessor.Web/Configuration/Resources/processing.config b/src/ImageProcessor.Web/Configuration/Resources/processing.config
index e1ecdfa59..ce00ddffa 100644
--- a/src/ImageProcessor.Web/Configuration/Resources/processing.config
+++ b/src/ImageProcessor.Web/Configuration/Resources/processing.config
@@ -25,6 +25,7 @@
+
diff --git a/src/ImageProcessor.Web/ImageProcessor.Web.csproj b/src/ImageProcessor.Web/ImageProcessor.Web.csproj
index 7b6612b12..f13068324 100644
--- a/src/ImageProcessor.Web/ImageProcessor.Web.csproj
+++ b/src/ImageProcessor.Web/ImageProcessor.Web.csproj
@@ -82,6 +82,7 @@
+
diff --git a/src/ImageProcessor.Web/Processors/Meta.cs b/src/ImageProcessor.Web/Processors/Meta.cs
new file mode 100644
index 000000000..14aee5714
--- /dev/null
+++ b/src/ImageProcessor.Web/Processors/Meta.cs
@@ -0,0 +1,92 @@
+// --------------------------------------------------------------------------------------------------------------------
+//
+// Copyright (c) James South.
+// Licensed under the Apache License, Version 2.0.
+//
+//
+// Encapsulates methods to control preservation of meta information.
+//
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace ImageProcessor.Web.Processors
+{
+ using System.Text.RegularExpressions;
+ using ImageProcessor.Processors;
+
+ ///
+ /// Encapsulates methods to control preservation of meta information.
+ ///
+ public class Meta : IWebGraphicsProcessor
+ {
+ ///
+ /// The regular expression to search strings for.
+ ///
+ private static readonly Regex QueryRegex = new Regex(@"meta=(true|false)", RegexOptions.Compiled);
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public Meta()
+ {
+ this.Processor = new ImageProcessor.Processors.Meta();
+ }
+
+ ///
+ /// Gets the regular expression to search strings for.
+ ///
+ public Regex RegexPattern
+ {
+ get
+ {
+ return QueryRegex;
+ }
+ }
+
+ ///
+ /// Gets the order in which this processor is to be used in a chain.
+ ///
+ public int SortOrder { get; private set; }
+
+ ///
+ /// Gets the associated graphics processor.
+ ///
+ public IGraphicsProcessor Processor { get; private set; }
+
+ ///
+ /// The position in the original string where the first character of the captured substring was found.
+ ///
+ ///
+ /// The query string to search.
+ ///
+ ///
+ /// The zero-based starting position in the original string where the captured substring was found.
+ ///
+ public int MatchRegexIndex(string queryString)
+ {
+ int index = 0;
+
+ // Set the sort order to max to allow filtering.
+ this.SortOrder = int.MaxValue;
+
+ foreach (Match match in this.RegexPattern.Matches(queryString))
+ {
+ if (match.Success)
+ {
+ if (index == 0)
+ {
+ // Set the index on the first instance only.
+ this.SortOrder = match.Index;
+
+ bool preserve = bool.Parse(match.Value.Split('=')[1]);
+
+ this.Processor.DynamicParameter = preserve;
+ }
+
+ index += 1;
+ }
+ }
+
+ return this.SortOrder;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/ImageProcessor/ImageProcessor.csproj b/src/ImageProcessor/ImageProcessor.csproj
index 9d163d5c7..bdaeb9ba9 100644
--- a/src/ImageProcessor/ImageProcessor.csproj
+++ b/src/ImageProcessor/ImageProcessor.csproj
@@ -118,6 +118,7 @@
+
diff --git a/src/ImageProcessor/Processors/Meta.cs b/src/ImageProcessor/Processors/Meta.cs
new file mode 100644
index 000000000..5eb2eabeb
--- /dev/null
+++ b/src/ImageProcessor/Processors/Meta.cs
@@ -0,0 +1,74 @@
+// --------------------------------------------------------------------------------------------------------------------
+//
+// Copyright (c) James South.
+// Licensed under the Apache License, Version 2.0.
+//
+//
+// Encapsulates methods to control preservation of meta information.
+//
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace ImageProcessor.Processors
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Drawing;
+
+ using ImageProcessor.Common.Exceptions;
+
+ ///
+ /// Encapsulates methods to control preservation of meta information.
+ ///
+ public class Meta : IGraphicsProcessor
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public Meta()
+ {
+ this.Settings = new Dictionary();
+ }
+
+ ///
+ /// Gets or sets DynamicParameter.
+ ///
+ public dynamic DynamicParameter
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// Gets or sets any additional settings required by the processor.
+ ///
+ public Dictionary Settings
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// Processes the image.
+ ///
+ ///
+ /// The current instance of the class containing
+ /// the image to process.
+ ///
+ ///
+ /// The processed image from the current instance of the class.
+ ///
+ public Image ProcessImage(ImageFactory factory)
+ {
+ try
+ {
+ factory.PreserveExifData = this.DynamicParameter;
+ }
+ catch (Exception ex)
+ {
+ throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
+ }
+
+ return factory.Image;
+ }
+ }
+}