diff --git a/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs b/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs
index 21c3e4a31..6b3712e39 100644
--- a/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs
+++ b/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs
@@ -49,7 +49,7 @@ namespace ImageProcessor.Web.HttpModules
///
/// The regular expression to search strings for.
///
- private static readonly Regex PresetRegex = new Regex(@"preset=[^&]*", RegexOptions.Compiled);
+ private static readonly Regex PresetRegex = new Regex(@"preset=[^&]+", RegexOptions.Compiled);
///
/// The assembly version.
@@ -407,6 +407,9 @@ namespace ImageProcessor.Web.HttpModules
{
responseStream.CopyTo(memoryStream);
+ // Reset the position of the stream to ensure we're reading the correct part.
+ memoryStream.Position = 0;
+
// Process the Image
imageFactory.Load(memoryStream)
.AddQueryString(queryString)
diff --git a/src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj b/src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj
index e302a38ff..f8eb6861a 100644
--- a/src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj
+++ b/src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj
@@ -78,6 +78,7 @@
+
diff --git a/src/ImageProcessor.Web/NET45/Processors/Alpha.cs b/src/ImageProcessor.Web/NET45/Processors/Alpha.cs
index 75993a702..760fca99e 100644
--- a/src/ImageProcessor.Web/NET45/Processors/Alpha.cs
+++ b/src/ImageProcessor.Web/NET45/Processors/Alpha.cs
@@ -13,7 +13,7 @@
///
/// The regular expression to search strings for.
///
- private static readonly Regex QueryRegex = new Regex(@"alpha=[^&|,]*", RegexOptions.Compiled);
+ private static readonly Regex QueryRegex = new Regex(@"alpha=[^&|,]+", RegexOptions.Compiled);
///
/// Initializes a new instance of the class.
diff --git a/src/ImageProcessor.Web/NET45/Processors/BackgroundColor.cs b/src/ImageProcessor.Web/NET45/Processors/BackgroundColor.cs
index c617f72a7..edc9c3b68 100644
--- a/src/ImageProcessor.Web/NET45/Processors/BackgroundColor.cs
+++ b/src/ImageProcessor.Web/NET45/Processors/BackgroundColor.cs
@@ -22,7 +22,7 @@ namespace ImageProcessor.Web.Processors
///
/// The regular expression to search strings for.
///
- private static readonly Regex QueryRegex = new Regex(@"bgcolor(=|-)[^&]*", RegexOptions.Compiled);
+ private static readonly Regex QueryRegex = new Regex(@"bgcolor(=|-)[^&]+", RegexOptions.Compiled);
///
/// Initializes a new instance of the class.
diff --git a/src/ImageProcessor.Web/NET45/Processors/Brightness.cs b/src/ImageProcessor.Web/NET45/Processors/Brightness.cs
index 602d34b1c..abd8528d1 100644
--- a/src/ImageProcessor.Web/NET45/Processors/Brightness.cs
+++ b/src/ImageProcessor.Web/NET45/Processors/Brightness.cs
@@ -22,7 +22,7 @@ namespace ImageProcessor.Web.Processors
///
/// The regular expression to search strings for.
///
- private static readonly Regex QueryRegex = new Regex(@"brightness=[^&|,]*", RegexOptions.Compiled);
+ private static readonly Regex QueryRegex = new Regex(@"brightness=[^&|,]+", RegexOptions.Compiled);
///
/// Initializes a new instance of the class.
diff --git a/src/ImageProcessor.Web/NET45/Processors/Contrast.cs b/src/ImageProcessor.Web/NET45/Processors/Contrast.cs
index 09ec2808c..2b9a501af 100644
--- a/src/ImageProcessor.Web/NET45/Processors/Contrast.cs
+++ b/src/ImageProcessor.Web/NET45/Processors/Contrast.cs
@@ -22,7 +22,7 @@ namespace ImageProcessor.Web.Processors
///
/// The regular expression to search strings for.
///
- private static readonly Regex QueryRegex = new Regex(@"contrast=[^&|,]*", RegexOptions.Compiled);
+ private static readonly Regex QueryRegex = new Regex(@"contrast=[^&|,]+", RegexOptions.Compiled);
///
/// Initializes a new instance of the class.
diff --git a/src/ImageProcessor.Web/NET45/Processors/Crop.cs b/src/ImageProcessor.Web/NET45/Processors/Crop.cs
index 4ca186d5c..a446e37b8 100644
--- a/src/ImageProcessor.Web/NET45/Processors/Crop.cs
+++ b/src/ImageProcessor.Web/NET45/Processors/Crop.cs
@@ -25,7 +25,7 @@ namespace ImageProcessor.Web.Processors
/// The regular expression to search strings for.
///
///
- private static readonly Regex QueryRegex = new Regex(@"(crop=|cropmode=)[^&]*", RegexOptions.Compiled);
+ private static readonly Regex QueryRegex = new Regex(@"(crop=|cropmode=)[^&]+", RegexOptions.Compiled);
///
/// The coordinate regex.
diff --git a/src/ImageProcessor.Web/NET45/Processors/GaussianBlur.cs b/src/ImageProcessor.Web/NET45/Processors/GaussianBlur.cs
index 88f107ee7..d6e66232b 100644
--- a/src/ImageProcessor.Web/NET45/Processors/GaussianBlur.cs
+++ b/src/ImageProcessor.Web/NET45/Processors/GaussianBlur.cs
@@ -23,7 +23,7 @@ namespace ImageProcessor.Web.Processors
///
/// The regular expression to search strings for.
///
- private static readonly Regex QueryRegex = new Regex(@"blur=[^&]*", RegexOptions.Compiled);
+ private static readonly Regex QueryRegex = new Regex(@"blur=[^&]+", RegexOptions.Compiled);
///
/// Initializes a new instance of the class.
diff --git a/src/ImageProcessor.Web/NET45/Processors/GaussianSharpen.cs b/src/ImageProcessor.Web/NET45/Processors/GaussianSharpen.cs
index 60d0235cf..67adf7b3d 100644
--- a/src/ImageProcessor.Web/NET45/Processors/GaussianSharpen.cs
+++ b/src/ImageProcessor.Web/NET45/Processors/GaussianSharpen.cs
@@ -23,7 +23,7 @@ namespace ImageProcessor.Web.Processors
///
/// The regular expression to search strings for.
///
- private static readonly Regex QueryRegex = new Regex(@"sharpen=[^&]*", RegexOptions.Compiled);
+ private static readonly Regex QueryRegex = new Regex(@"sharpen=[^&]+", RegexOptions.Compiled);
///
/// Initializes a new instance of the class.
diff --git a/src/ImageProcessor.Web/NET45/Processors/Quality.cs b/src/ImageProcessor.Web/NET45/Processors/Quality.cs
index fa11777db..b392aecb5 100644
--- a/src/ImageProcessor.Web/NET45/Processors/Quality.cs
+++ b/src/ImageProcessor.Web/NET45/Processors/Quality.cs
@@ -23,7 +23,7 @@ namespace ImageProcessor.Web.Processors
///
/// The regular expression to search strings for.
///
- private static readonly Regex QueryRegex = new Regex(@"quality=[^&|,]*", RegexOptions.Compiled);
+ private static readonly Regex QueryRegex = new Regex(@"quality=[^&|,]+", RegexOptions.Compiled);
///
/// Initializes a new instance of the class.
diff --git a/src/ImageProcessor.Web/NET45/Processors/Rotate.cs b/src/ImageProcessor.Web/NET45/Processors/Rotate.cs
index 74a707d36..7ab41f7da 100644
--- a/src/ImageProcessor.Web/NET45/Processors/Rotate.cs
+++ b/src/ImageProcessor.Web/NET45/Processors/Rotate.cs
@@ -22,7 +22,7 @@ namespace ImageProcessor.Web.Processors
///
/// The regular expression to search strings for.
///
- private static readonly Regex QueryRegex = new Regex(@"(rotate|angle)(=|-)[^&|,]*", RegexOptions.Compiled);
+ private static readonly Regex QueryRegex = new Regex(@"(rotate|angle)(=|-)[^&|,]+", RegexOptions.Compiled);
///
/// Initializes a new instance of the class.
diff --git a/src/ImageProcessor.Web/NET45/Processors/Saturation.cs b/src/ImageProcessor.Web/NET45/Processors/Saturation.cs
index 469a19ba6..3a98bde7e 100644
--- a/src/ImageProcessor.Web/NET45/Processors/Saturation.cs
+++ b/src/ImageProcessor.Web/NET45/Processors/Saturation.cs
@@ -25,7 +25,7 @@ namespace ImageProcessor.Web.Processors
///
/// The regular expression to search strings for.
///
- private static readonly Regex QueryRegex = new Regex(@"saturation=[^&|,]*", RegexOptions.Compiled);
+ private static readonly Regex QueryRegex = new Regex(@"saturation=[^&|,]+", RegexOptions.Compiled);
///
/// Initializes a new instance of the class.
diff --git a/src/ImageProcessor.Web/NET45/Processors/Tint.cs b/src/ImageProcessor.Web/NET45/Processors/Tint.cs
index d6621b003..73fef8b3f 100644
--- a/src/ImageProcessor.Web/NET45/Processors/Tint.cs
+++ b/src/ImageProcessor.Web/NET45/Processors/Tint.cs
@@ -22,7 +22,7 @@ namespace ImageProcessor.Web.Processors
///
/// The regular expression to search strings for.
///
- private static readonly Regex QueryRegex = new Regex(@"tint=[^&]*", RegexOptions.Compiled);
+ private static readonly Regex QueryRegex = new Regex(@"tint=[^&]+", RegexOptions.Compiled);
///
/// Initializes a new instance of the class.
diff --git a/src/ImageProcessor.Web/NET45/Processors/Vignette.cs b/src/ImageProcessor.Web/NET45/Processors/Vignette.cs
index 3982859b9..7dc7259d3 100644
--- a/src/ImageProcessor.Web/NET45/Processors/Vignette.cs
+++ b/src/ImageProcessor.Web/NET45/Processors/Vignette.cs
@@ -23,7 +23,7 @@ namespace ImageProcessor.Web.Processors
///
/// The regular expression to search strings for.
///
- private static readonly Regex QueryRegex = new Regex(@"vignette=(true)?[^&]*", RegexOptions.Compiled);
+ private static readonly Regex QueryRegex = new Regex(@"vignette(=true)?[^&]+", RegexOptions.Compiled);
///
/// Initializes a new instance of the class.
diff --git a/src/ImageProcessor.Web/NET45/Processors/Watermark.cs b/src/ImageProcessor.Web/NET45/Processors/Watermark.cs
new file mode 100644
index 000000000..641131761
--- /dev/null
+++ b/src/ImageProcessor.Web/NET45/Processors/Watermark.cs
@@ -0,0 +1,339 @@
+// --------------------------------------------------------------------------------------------------------------------
+//
+// Copyright (c) James South.
+// Licensed under the Apache License, Version 2.0.
+//
+//
+// Encapsulates methods to add a watermark text overlay to an image.
+//
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace ImageProcessor.Web.Processors
+{
+ using System.Drawing;
+ using System.Globalization;
+ using System.Linq;
+ using System.Text.RegularExpressions;
+ using ImageProcessor.Core.Common.Extensions;
+ using ImageProcessor.Imaging;
+ using ImageProcessor.Processors;
+ using ImageProcessor.Web.Helpers;
+
+ ///
+ /// Encapsulates methods to add a watermark text overlay to an image.
+ ///
+ public class Watermark : IWebGraphicsProcessor
+ {
+ ///
+ /// The regular expression to search strings for.
+ ///
+ private static readonly Regex QueryRegex = new Regex(@"watermark=[^&]+", RegexOptions.Compiled);
+
+ ///
+ /// The regular expression to search strings for the text attribute.
+ ///
+ private static readonly Regex TextRegex = new Regex(@"(watermark=[^text-]|text-)[^/:?#\[\]@!$&'()*%\|,;=&]+", RegexOptions.Compiled);
+
+ ///
+ /// The regular expression to search strings for the position attribute.
+ ///
+ private static readonly Regex PositionRegex = new Regex(@"(text)?position(=|-)\d+[-,]\d+", RegexOptions.Compiled);
+
+ ///
+ /// The regular expression to search strings for the font size attribute.
+ ///
+ private static readonly Regex FontSizeRegex = new Regex(@"((font)?)size(=|-)\d{1,3}", RegexOptions.Compiled);
+
+ ///
+ /// The regular expression to search strings for the font style attribute.
+ ///
+ private static readonly Regex FontStyleRegex = new Regex(@"((font)?)style(=|-)(bold|italic|regular|strikeout|underline)", RegexOptions.Compiled);
+
+ ///
+ /// The regular expression to search strings for the font family attribute.
+ ///
+ private static readonly Regex FontFamilyRegex = new Regex(@"font(=|-)[^/:?#\[\]@!$&'()*%\|,;=0-9]+", RegexOptions.Compiled);
+
+ ///
+ /// The regular expression to search strings for the opacity attribute.
+ ///
+ private static readonly Regex OpacityRegex = new Regex(@"((font)?)opacity(=|-)(?:100|[1-9]?[0-9])", RegexOptions.Compiled);
+
+ ///
+ /// The regular expression to search strings for the shadow attribute.
+ ///
+ private static readonly Regex ShadowRegex = new Regex(@"((text)?)shadow(=|-)true", RegexOptions.Compiled);
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public Watermark()
+ {
+ this.Processor = new ImageProcessor.Processors.Watermark();
+ }
+
+ ///
+ /// 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;
+
+ TextLayer textLayer = new TextLayer
+ {
+ Text = this.ParseText(queryString),
+ Position = this.ParsePosition(queryString),
+ TextColor = this.ParseColor(queryString),
+ FontSize = this.ParseFontSize(queryString),
+ Font = this.ParseFontFamily(queryString),
+ Style = this.ParseFontStyle(queryString),
+ DropShadow = this.ParseDropShadow(queryString)
+ };
+
+ textLayer.Opacity = this.ParseOpacity(queryString, textLayer.TextColor);
+
+ this.Processor.DynamicParameter = textLayer;
+ }
+
+ index += 1;
+ }
+ }
+
+ return this.SortOrder;
+ }
+
+ #region Private Methods
+ ///
+ /// Returns the correct for the given string.
+ ///
+ ///
+ /// The input string containing the value to parse.
+ ///
+ ///
+ /// The correct for the given string.
+ ///
+ private string ParseText(string input)
+ {
+ foreach (Match match in TextRegex.Matches(input))
+ {
+ // split on text-
+ return match.Value.Split(new[] { '=', '-' })[1].Replace("+", " ");
+ }
+
+ return string.Empty;
+ }
+
+ ///
+ /// Returns the correct for the given string.
+ ///
+ ///
+ /// The input string containing the value to parse.
+ ///
+ ///
+ /// The correct
+ ///
+ private Point ParsePosition(string input)
+ {
+ foreach (Match match in PositionRegex.Matches(input))
+ {
+ int[] position = match.Value.ToPositiveIntegerArray();
+
+ if (position != null)
+ {
+ int x = position[0];
+ int y = position[1];
+
+ return new Point(x, y);
+ }
+ }
+
+ return Point.Empty;
+ }
+
+ ///
+ /// Returns the correct for the given string.
+ ///
+ ///
+ /// The input string containing the value to parse.
+ ///
+ ///
+ /// The correct
+ ///
+ private Color ParseColor(string input)
+ {
+ Color textColor = CommonParameterParserUtility.ParseColor(input);
+ if (!textColor.Equals(Color.Transparent))
+ {
+ return textColor;
+ }
+
+ return Color.Black;
+ }
+
+ ///
+ /// Returns the correct for the given string.
+ ///
+ ///
+ /// The input string containing the value to parse.
+ ///
+ ///
+ /// The correct
+ ///
+ private int ParseFontSize(string input)
+ {
+ foreach (Match match in FontSizeRegex.Matches(input))
+ {
+ // split on size-value
+ return int.Parse(match.Value.Split(new[] { '=', '-' })[1], CultureInfo.InvariantCulture);
+ }
+
+ // Matches the default number in TextLayer.
+ return 48;
+ }
+
+ ///
+ /// Returns the correct for the given string.
+ ///
+ ///
+ /// The string containing the respective font style.
+ ///
+ ///
+ /// The correct
+ ///
+ private FontStyle ParseFontStyle(string input)
+ {
+ FontStyle fontStyle = FontStyle.Bold;
+
+ foreach (Match match in FontStyleRegex.Matches(input))
+ {
+ // split on style-
+ switch (match.Value.Split(new[]
+ {
+ '=', '-'
+ })[1])
+ {
+ case "italic":
+ fontStyle = FontStyle.Italic;
+ break;
+ case "regular":
+ fontStyle = FontStyle.Regular;
+ break;
+ case "strikeout":
+ fontStyle = FontStyle.Strikeout;
+ break;
+ case "underline":
+ fontStyle = FontStyle.Underline;
+ break;
+ }
+ }
+
+ return fontStyle;
+ }
+
+ ///
+ /// Returns the correct containing the font family for the given string.
+ ///
+ ///
+ /// The input string containing the value to parse.
+ ///
+ ///
+ /// The correct containing the font family for the given string.
+ ///
+ private string ParseFontFamily(string input)
+ {
+ foreach (Match match in FontFamilyRegex.Matches(input))
+ {
+ // split on font-
+ string font = match.Value.Split(new[] { '=', '-' })[1].Replace("+", " ");
+
+ return font;
+ }
+
+ return string.Empty;
+ }
+
+ ///
+ /// Returns the correct containing the opacity for the given string.
+ ///
+ ///
+ /// The input string containing the value to parse.
+ ///
+ ///
+ /// The of the current .
+ ///
+ ///
+ /// The correct containing the opacity for the given string.
+ ///
+ private int ParseOpacity(string input, Color color)
+ {
+ if (color.A < 255)
+ {
+ return color.A;
+ }
+
+ foreach (Match match in OpacityRegex.Matches(input))
+ {
+ // Split on opacity-
+ return int.Parse(match.Value.Split(new[] { '=', '-' })[1], CultureInfo.InvariantCulture);
+ }
+
+ // Full opacity - matches the Textlayer default.
+ return 100;
+ }
+
+ ///
+ /// Returns a value indicating whether the watermark is to have a shadow.
+ ///
+ ///
+ /// The input string containing the value to parse.
+ ///
+ ///
+ /// The true if the watermark is to have a shadow; otherwise false.
+ ///
+ private bool ParseDropShadow(string input)
+ {
+ return ShadowRegex.Matches(input).Cast().Any();
+ }
+
+ #endregion
+ }
+}
diff --git a/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs b/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs
index d3b6f9c56..3693d23e1 100644
--- a/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs
+++ b/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs
@@ -34,6 +34,9 @@ namespace ImageProcessor.Imaging.Formats
///
public static ISupportedImageFormat GetFormat(Stream stream)
{
+ // Reset the position of the stream to ensure we're reading the correct part.
+ stream.Position = 0;
+
IEnumerable supportedImageFormats =
ImageProcessorBootstrapper.Instance.SupportedImageFormats;
diff --git a/src/ImageProcessor/Processors/Watermark.cs b/src/ImageProcessor/Processors/Watermark.cs
index e911a443f..136439fba 100644
--- a/src/ImageProcessor/Processors/Watermark.cs
+++ b/src/ImageProcessor/Processors/Watermark.cs
@@ -4,88 +4,23 @@
// Licensed under the Apache License, Version 2.0.
//
//
-// Encapsulates methods to change the alpha component of the image to effect its transparency.
+// Encapsulates methods to add a watermark text overlay to an image.
//
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Processors
{
- #region Using
-
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Text;
- using System.Globalization;
- using System.Linq;
- using System.Text.RegularExpressions;
-
- using ImageProcessor.Core.Common.Extensions;
using ImageProcessor.Imaging;
- #endregion
///
- /// Encapsulates methods to change the alpha component of the image to effect its transparency.
+ /// Encapsulates methods to add a watermark text overlay to an image.
///
public class Watermark : IGraphicsProcessor
{
- ///
- /// The regular expression to search strings for.
- ///
- private static readonly Regex QueryRegex = new Regex(@"watermark=[^&]*", RegexOptions.Compiled);
-
- ///
- /// The regular expression to search strings for the text attribute.
- ///
- private static readonly Regex TextRegex = new Regex(@"text-[^/:?#\[\]@!$&'()*%\|,;=]+", RegexOptions.Compiled);
-
- ///
- /// The regular expression to search strings for the position attribute.
- ///
- private static readonly Regex PositionRegex = new Regex(@"position-\d+[-,]\d+", RegexOptions.Compiled);
-
- ///
- /// The regular expression to search strings for the color attribute.
- ///
- private static readonly Regex ColorRegex = new Regex(@"color-([0-9a-fA-F]{3}){1,2}", RegexOptions.Compiled);
-
- ///
- /// The regular expression to search strings for the font size attribute.
- ///
- private static readonly Regex FontSizeRegex = new Regex(@"size-\d{1,3}", RegexOptions.Compiled);
-
- ///
- /// The regular expression to search strings for the font style attribute.
- ///
- private static readonly Regex FontStyleRegex = new Regex(@"style-(bold|italic|regular|strikeout|underline)", RegexOptions.Compiled);
-
- ///
- /// The regular expression to search strings for the font family attribute.
- ///
- private static readonly Regex FontFamilyRegex = new Regex(@"font-[^/:?#\[\]@!$&'()*%\|,;=0-9]+", RegexOptions.Compiled);
-
- ///
- /// The regular expression to search strings for the opacity attribute.
- ///
- private static readonly Regex OpacityRegex = new Regex(@"opacity-(?:100|[1-9]?[0-9])", RegexOptions.Compiled);
-
- ///
- /// The regular expression to search strings for the shadow attribute.
- ///
- private static readonly Regex ShadowRegex = new Regex(@"shadow-true", RegexOptions.Compiled);
-
- #region IGraphicsProcessor Members
- ///
- /// Gets the regular expression to search strings for.
- ///
- public Regex RegexPattern
- {
- get
- {
- return QueryRegex;
- }
- }
-
///
/// Gets or sets DynamicParameter.
///
@@ -95,15 +30,6 @@ namespace ImageProcessor.Processors
set;
}
- ///
- /// Gets the order in which this processor is to be used in a chain.
- ///
- public int SortOrder
- {
- get;
- private set;
- }
-
///
/// Gets or sets any additional settings required by the processor.
///
@@ -113,54 +39,6 @@ namespace ImageProcessor.Processors
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;
-
- TextLayer textLayer = new TextLayer();
-
- string toParse = match.Value;
-
- textLayer.Text = this.ParseText(toParse);
- textLayer.Position = this.ParsePosition(toParse);
- textLayer.TextColor = this.ParseColor(toParse);
- textLayer.FontSize = this.ParseFontSize(toParse);
- textLayer.Font = this.ParseFontFamily(toParse);
- textLayer.Style = this.ParseFontStyle(toParse);
- textLayer.Opacity = this.ParseOpacity(toParse);
- textLayer.DropShadow = this.ParseDropShadow(toParse);
-
- this.DynamicParameter = textLayer;
- }
-
- index += 1;
- }
- }
-
- return this.SortOrder;
- }
-
///
/// Processes the image.
///
@@ -254,20 +132,18 @@ namespace ImageProcessor.Processors
return image;
}
- #endregion
- #region Private Methods
///
- /// Returns the correct for the given parameters
+ /// Returns the correct for the given parameters.
///
///
- /// The font.
+ /// The name of the font.
///
///
/// The font size.
///
///
- /// The font style.
+ /// The style.
///
///
/// The correct
@@ -289,188 +165,5 @@ namespace ImageProcessor.Processors
}
}
}
-
- ///
- /// Returns the correct for the given string.
- ///
- ///
- /// The input string containing the value to parse.
- ///
- ///
- /// The correct for the given string.
- ///
- private string ParseText(string input)
- {
- foreach (Match match in TextRegex.Matches(input))
- {
- // split on text-
- return match.Value.Split('-')[1].Replace("+", " ");
- }
-
- return string.Empty;
- }
-
- ///
- /// Returns the correct for the given string.
- ///
- ///
- /// The input string containing the value to parse.
- ///
- ///
- /// The correct
- ///
- private Point ParsePosition(string input)
- {
- foreach (Match match in PositionRegex.Matches(input))
- {
- int[] position = match.Value.ToPositiveIntegerArray();
-
- if (position != null)
- {
- int x = position[0];
- int y = position[1];
-
- return new Point(x, y);
- }
- }
-
- return Point.Empty;
- }
-
- ///
- /// Returns the correct for the given string.
- ///
- ///
- /// The input string containing the value to parse.
- ///
- ///
- /// The correct
- ///
- private Color ParseColor(string input)
- {
- foreach (Match match in ColorRegex.Matches(input))
- {
- // split on color-hex
- return ColorTranslator.FromHtml("#" + match.Value.Split('-')[1]);
- }
-
- return Color.Black;
- }
-
- ///
- /// Returns the correct for the given string.
- ///
- ///
- /// The input string containing the value to parse.
- ///
- ///
- /// The correct
- ///
- private int ParseFontSize(string input)
- {
- foreach (Match match in FontSizeRegex.Matches(input))
- {
- // split on size-value
- return int.Parse(match.Value.Split('-')[1], CultureInfo.InvariantCulture);
- }
-
- // Matches the default number in TextLayer.
- return 48;
- }
-
- ///
- /// Returns the correct for the given string.
- ///
- ///
- /// The string containing the respective font style.
- ///
- ///
- /// The correct
- ///
- private FontStyle ParseFontStyle(string input)
- {
- FontStyle fontStyle = FontStyle.Bold;
-
- foreach (Match match in FontStyleRegex.Matches(input))
- {
- // split on style-
- switch (match.Value.Split('-')[1])
- {
- case "italic":
- fontStyle = FontStyle.Italic;
- break;
- case "regular":
- fontStyle = FontStyle.Regular;
- break;
- case "strikeout":
- fontStyle = FontStyle.Strikeout;
- break;
- case "underline":
- fontStyle = FontStyle.Underline;
- break;
- }
- }
-
- return fontStyle;
- }
-
- ///
- /// Returns the correct containing the font family for the given string.
- ///
- ///
- /// The input string containing the value to parse.
- ///
- ///
- /// The correct containing the font family for the given string.
- ///
- private string ParseFontFamily(string input)
- {
- foreach (Match match in FontFamilyRegex.Matches(input))
- {
- // split on font-
- string font = match.Value.Split('-')[1].Replace("+", " ");
-
- return font;
- }
-
- return string.Empty;
- }
-
- ///
- /// Returns the correct containing the opacity for the given string.
- ///
- ///
- /// The input string containing the value to parse.
- ///
- ///
- /// The correct containing the opacity for the given string.
- ///
- private int ParseOpacity(string input)
- {
- foreach (Match match in OpacityRegex.Matches(input))
- {
- // split on opacity-
- return int.Parse(match.Value.Split('-')[1], CultureInfo.InvariantCulture);
- }
-
- // full opacity - matches the Textlayer default.
- return 100;
- }
-
- ///
- /// Returns a value indicating whether the watermark is to have a shadow.
- ///
- ///
- /// The input string containing the value to parse.
- ///
- ///
- /// The true if the watermark is to have a shadow; otherwise false.
- ///
- private bool ParseDropShadow(string input)
- {
- return ShadowRegex.Matches(input).Cast().Any();
- }
-
- #endregion
}
}