diff --git a/src/ImageProcessor.Web/Helpers/ImageHelpers.cs b/src/ImageProcessor.Web/Helpers/ImageHelpers.cs index b09ff16b4..f784cccf6 100644 --- a/src/ImageProcessor.Web/Helpers/ImageHelpers.cs +++ b/src/ImageProcessor.Web/Helpers/ImageHelpers.cs @@ -10,7 +10,6 @@ namespace ImageProcessor.Web.Helpers { - using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; @@ -83,7 +82,7 @@ namespace ImageProcessor.Web.Helpers { trimmed = trimmed.Replace(queryString, string.Empty); } - + match = FormatRegex.Match(trimmed); } diff --git a/src/ImageProcessor.Web/Helpers/QuerystringParser/GenericListTypeConverter.cs b/src/ImageProcessor.Web/Helpers/QuerystringParser/GenericListTypeConverter.cs index caf0bf281..e48aff70e 100644 --- a/src/ImageProcessor.Web/Helpers/QuerystringParser/GenericListTypeConverter.cs +++ b/src/ImageProcessor.Web/Helpers/QuerystringParser/GenericListTypeConverter.cs @@ -62,8 +62,7 @@ namespace ImageProcessor.Web.Helpers { if (sourceType == typeof(string)) { - string[] items = this.GetStringArray(sourceType.ToString()); - return items.Any(); + return true; } return base.CanConvertFrom(context, sourceType); @@ -89,7 +88,7 @@ namespace ImageProcessor.Web.Helpers string input = value as string; if (input != null) { - string[] items = this.GetStringArray(input); + string[] items = this.GetStringArray(input, culture); List result = new List(); @@ -136,7 +135,13 @@ namespace ImageProcessor.Web.Helpers { if (destinationType == typeof(string)) { - return string.Join(",", (IList)value); + if (culture == null) + { + culture = CultureInfo.CurrentCulture; + } + + string separator = culture.TextInfo.ListSeparator; + return string.Join(separator, (IList)value); } return base.ConvertTo(context, culture, value, destinationType); @@ -148,12 +153,21 @@ namespace ImageProcessor.Web.Helpers /// /// The input string to split. /// + /// + /// A . The current culture to split string by. + /// /// /// The array from the comma separated values. /// - protected string[] GetStringArray(string input) + protected string[] GetStringArray(string input, CultureInfo culture) { - string[] result = input.Split(',').Select(s => s.Trim()).ToArray(); + if (culture == null) + { + culture = CultureInfo.CurrentCulture; + } + + char separator = culture.TextInfo.ListSeparator[0]; + string[] result = input.Split(separator).Select(s => s.Trim()).ToArray(); return result; } diff --git a/src/ImageProcessor.Web/Helpers/QuerystringParser/QueryParamParser.cs b/src/ImageProcessor.Web/Helpers/QuerystringParser/QueryParamParser.cs index b8abcc898..24a3e252f 100644 --- a/src/ImageProcessor.Web/Helpers/QuerystringParser/QueryParamParser.cs +++ b/src/ImageProcessor.Web/Helpers/QuerystringParser/QueryParamParser.cs @@ -17,6 +17,7 @@ namespace ImageProcessor.Web.Helpers using System.Drawing; using System.Globalization; using System.Linq.Expressions; + using System.Web; /// /// The query parameter parser that converts string values to different types. @@ -103,7 +104,7 @@ namespace ImageProcessor.Web.Helpers try { // ReSharper disable once AssignNullToNotNullAttribute - return converter.ConvertFrom(null, culture, value); + return converter.ConvertFrom(null, culture, HttpUtility.UrlDecode(value)); } catch { @@ -159,6 +160,8 @@ namespace ImageProcessor.Web.Helpers this.AddTypeConverter(typeof(List), typeof(GenericListTypeConverter)); this.AddTypeConverter(typeof(List), typeof(GenericListTypeConverter)); + + this.AddTypeConverter(typeof(List), typeof(GenericListTypeConverter)); } /// @@ -183,6 +186,8 @@ namespace ImageProcessor.Web.Helpers this.AddTypeConverter(typeof(double[]), typeof(GenericArrayTypeConverter)); this.AddTypeConverter(typeof(string[]), typeof(GenericArrayTypeConverter)); + + this.AddTypeConverter(typeof(Color[]), typeof(GenericArrayTypeConverter)); } /// diff --git a/src/ImageProcessor.Web/Processors/Alpha.cs b/src/ImageProcessor.Web/Processors/Alpha.cs index 1c93e1422..5be42894b 100644 --- a/src/ImageProcessor.Web/Processors/Alpha.cs +++ b/src/ImageProcessor.Web/Processors/Alpha.cs @@ -27,7 +27,7 @@ namespace ImageProcessor.Web.Processors /// /// 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=\d+", RegexOptions.Compiled); /// /// Initializes a new instance of the class. diff --git a/src/ImageProcessor.Web/Processors/Brightness.cs b/src/ImageProcessor.Web/Processors/Brightness.cs index 46c36d2a9..0415d7de3 100644 --- a/src/ImageProcessor.Web/Processors/Brightness.cs +++ b/src/ImageProcessor.Web/Processors/Brightness.cs @@ -26,7 +26,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=\d+", RegexOptions.Compiled); /// /// Initializes a new instance of the class. diff --git a/src/ImageProcessor.Web/Processors/Contrast.cs b/src/ImageProcessor.Web/Processors/Contrast.cs index 137e1f25e..da1e79021 100644 --- a/src/ImageProcessor.Web/Processors/Contrast.cs +++ b/src/ImageProcessor.Web/Processors/Contrast.cs @@ -26,7 +26,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=\d+", RegexOptions.Compiled); /// /// Initializes a new instance of the class. diff --git a/src/ImageProcessor.Web/Processors/Hue.cs b/src/ImageProcessor.Web/Processors/Hue.cs index 43bdbae00..d944bc828 100644 --- a/src/ImageProcessor.Web/Processors/Hue.cs +++ b/src/ImageProcessor.Web/Processors/Hue.cs @@ -29,7 +29,7 @@ namespace ImageProcessor.Web.Processors /// /// The regular expression to search strings for. /// - private static readonly Regex QueryRegex = new Regex(@"hue=[^&]", RegexOptions.Compiled); + private static readonly Regex QueryRegex = new Regex(@"hue=\d+", RegexOptions.Compiled); /// /// Initializes a new instance of the class. diff --git a/src/ImageProcessor.Web/Processors/Mask.cs b/src/ImageProcessor.Web/Processors/Mask.cs index 241cae874..a3641206a 100644 --- a/src/ImageProcessor.Web/Processors/Mask.cs +++ b/src/ImageProcessor.Web/Processors/Mask.cs @@ -12,14 +12,14 @@ namespace ImageProcessor.Web.Processors { using System; + using System.Collections.Specialized; using System.Drawing; using System.IO; - using System.Text; using System.Text.RegularExpressions; + using System.Web; using System.Web.Hosting; using ImageProcessor.Processors; - using ImageProcessor.Web.Extensions; using ImageProcessor.Web.Helpers; /// @@ -31,17 +31,7 @@ namespace ImageProcessor.Web.Processors /// /// The regular expression to search strings for. /// - private static readonly Regex QueryRegex = new Regex(@"(mask=|mask.\w+=)[^&]+", RegexOptions.Compiled); - - /// - /// The mask image regex. - /// - private static readonly Regex ImageRegex = new Regex(@"mask=[\w+-]+." + ImageHelpers.ExtensionRegexPattern); - - /// - /// The point regex. - /// - private static readonly Regex PointRegex = new Regex(@"mask.position=\d+,\d+", RegexOptions.Compiled); + private static readonly Regex QueryRegex = new Regex(@"mask=[\w+-]+." + ImageHelpers.ExtensionRegexPattern); /// /// Initializes a new instance of the class. @@ -81,36 +71,18 @@ namespace ImageProcessor.Web.Processors /// public int MatchRegexIndex(string queryString) { - int index = 0; - - // Set the sort order to max to allow filtering. this.SortOrder = int.MaxValue; + Match match = this.RegexPattern.Match(queryString); - // First merge the matches so we can parse . - StringBuilder stringBuilder = new StringBuilder(); - - foreach (Match match in this.RegexPattern.Matches(queryString)) + if (match.Success) { - if (match.Success) - { - if (index == 0) - { - // Set the index on the first instance only. - this.SortOrder = match.Index; - } - - stringBuilder.Append(match.Value); + this.SortOrder = match.Index; + NameValueCollection queryCollection = HttpUtility.ParseQueryString(queryString); + Image image = this.ParseImage(queryCollection["mask"]); + Point? position = queryCollection["mask.position"] != null + ? QueryParamParser.Instance.ParseValue(queryCollection["mask.position"]) + : (Point?)null; - index += 1; - } - } - - if (this.SortOrder < int.MaxValue) - { - // Match syntax - string toParse = stringBuilder.ToString(); - Image image = this.ParseImage(toParse); - Point? position = this.ParsePoint(toParse); this.Processor.DynamicParameter = new Tuple(image, position); } @@ -118,13 +90,13 @@ namespace ImageProcessor.Web.Processors } /// - /// Returns the correct size of pixels. + /// Returns an image from the given input path. /// /// /// The input containing the value to parse. /// /// - /// The representing the pixel size. + /// The representing the given image path. /// public Image ParseImage(string input) { @@ -136,50 +108,19 @@ namespace ImageProcessor.Web.Processors if (!string.IsNullOrWhiteSpace(path) && path.StartsWith("~/")) { - Match match = ImageRegex.Match(input); - - if (match.Success) + string imagePath = HostingEnvironment.MapPath(path); + if (imagePath != null) { - string imagePath = HostingEnvironment.MapPath(path); - if (imagePath != null) + imagePath = Path.Combine(imagePath, input); + using (ImageFactory factory = new ImageFactory()) { - imagePath = Path.Combine(imagePath, match.Value.Split('=')[1]); - using (ImageFactory factory = new ImageFactory()) - { - factory.Load(imagePath); - image = new Bitmap(factory.Image); - } + factory.Load(imagePath); + image = new Bitmap(factory.Image); } } } return image; } - - /// - /// Returns the correct for the given string. - /// - /// - /// The input string containing the value to parse. - /// - /// - /// The correct - /// - private Point? ParsePoint(string input) - { - int[] dimensions = { }; - Match match = PointRegex.Match(input); - if (match.Success) - { - dimensions = match.Value.ToPositiveIntegerArray(); - } - - if (dimensions.Length == 2) - { - return new Point(dimensions[0], dimensions[1]); - } - - return null; - } } } diff --git a/src/ImageProcessor.Web/Processors/Meta.cs b/src/ImageProcessor.Web/Processors/Meta.cs index 14aee5714..b6ea4bd79 100644 --- a/src/ImageProcessor.Web/Processors/Meta.cs +++ b/src/ImageProcessor.Web/Processors/Meta.cs @@ -63,27 +63,13 @@ namespace ImageProcessor.Web.Processors /// 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)) + Match match = this.RegexPattern.Match(queryString); + if (match.Success) { - 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; - } + this.SortOrder = match.Index; + bool preserve = bool.Parse(match.Value.Split('=')[1]); + this.Processor.DynamicParameter = preserve; } return this.SortOrder; diff --git a/src/ImageProcessor.Web/Processors/Overlay.cs b/src/ImageProcessor.Web/Processors/Overlay.cs index b2121b6a8..f1e782eb8 100644 --- a/src/ImageProcessor.Web/Processors/Overlay.cs +++ b/src/ImageProcessor.Web/Processors/Overlay.cs @@ -11,16 +11,15 @@ namespace ImageProcessor.Web.Processors { - using System; + using System.Collections.Specialized; using System.Drawing; using System.IO; - using System.Text; using System.Text.RegularExpressions; + using System.Web; using System.Web.Hosting; using ImageProcessor.Imaging; using ImageProcessor.Processors; - using ImageProcessor.Web.Extensions; using ImageProcessor.Web.Helpers; /// @@ -32,27 +31,7 @@ namespace ImageProcessor.Web.Processors /// /// The regular expression to search strings for. /// - private static readonly Regex QueryRegex = new Regex(@"(overlay=|overlay.\w+=)[^&]+", RegexOptions.Compiled); - - /// - /// The overlay image regex. - /// - private static readonly Regex ImageRegex = new Regex(@"overlay=[\w+-]+." + ImageHelpers.ExtensionRegexPattern); - - /// - /// The point regex. - /// - private static readonly Regex PointRegex = new Regex(@"overlay.position=\d+,\d+", RegexOptions.Compiled); - - /// - /// The size regex. - /// - private static readonly Regex SizeRegex = new Regex(@"overlay.size=\d+,\d+", RegexOptions.Compiled); - - /// - /// The opacity regex. - /// - private static readonly Regex OpacityRegex = new Regex(@"overlay.opacity=\d+", RegexOptions.Compiled); + private static readonly Regex QueryRegex = new Regex(@"overlay=[\w+-]+." + ImageHelpers.ExtensionRegexPattern); /// /// Initializes a new instance of the class. @@ -92,40 +71,30 @@ namespace ImageProcessor.Web.Processors /// public int MatchRegexIndex(string queryString) { - int index = 0; - - // Set the sort order to max to allow filtering. this.SortOrder = int.MaxValue; + Match match = this.RegexPattern.Match(queryString); - // First merge the matches so we can parse . - StringBuilder stringBuilder = new StringBuilder(); - - foreach (Match match in this.RegexPattern.Matches(queryString)) + if (match.Success) { - if (match.Success) - { - if (index == 0) - { - // Set the index on the first instance only. - this.SortOrder = match.Index; - } - - stringBuilder.Append(match.Value); - - index += 1; - } - } + this.SortOrder = match.Index; + NameValueCollection queryCollection = HttpUtility.ParseQueryString(queryString); + Image image = this.ParseImage(queryCollection["overlay"]); + + Point? position = queryCollection["overlay.position"] != null + ? QueryParamParser.Instance.ParseValue(queryCollection["overlay.position"]) + : (Point?)null; + + int opacity = queryCollection["overlay.opacity"] != null + ? QueryParamParser.Instance.ParseValue(queryCollection["overlay.opacity"]) + : 100; + Size size = QueryParamParser.Instance.ParseValue(queryCollection["overlay.size"]); - if (this.SortOrder < int.MaxValue) - { - // Match syntax - string toParse = stringBuilder.ToString(); this.Processor.DynamicParameter = new ImageLayer { - Image = this.ParseImage(toParse), - Position = this.ParsePoint(toParse), - Opacity = this.ParseOpacity(toParse), - Size = this.ParseSize(toParse) + Image = image, + Position = position, + Opacity = opacity, + Size = size }; } @@ -133,13 +102,13 @@ namespace ImageProcessor.Web.Processors } /// - /// Returns the correct size of pixels. + /// Returns an image from the given input path. /// /// /// The input containing the value to parse. /// /// - /// The representing the pixel size. + /// The representing the given image path. /// public Image ParseImage(string input) { @@ -151,94 +120,19 @@ namespace ImageProcessor.Web.Processors if (!string.IsNullOrWhiteSpace(path) && path.StartsWith("~/")) { - Match match = ImageRegex.Match(input); - - if (match.Success) + string imagePath = HostingEnvironment.MapPath(path); + if (imagePath != null) { - string imagePath = HostingEnvironment.MapPath(path); - if (imagePath != null) + imagePath = Path.Combine(imagePath, input); + using (ImageFactory factory = new ImageFactory()) { - imagePath = Path.Combine(imagePath, match.Value.Split('=')[1]); - using (ImageFactory factory = new ImageFactory()) - { - factory.Load(imagePath); - image = new Bitmap(factory.Image); - } + factory.Load(imagePath); + image = new Bitmap(factory.Image); } } } return image; } - - /// - /// Returns the correct for the given string. - /// - /// - /// The input string containing the value to parse. - /// - /// - /// The correct - /// - private Point? ParsePoint(string input) - { - int[] dimensions = { }; - - Match match = PointRegex.Match(input); - if (match.Success) - { - dimensions = match.Value.ToPositiveIntegerArray(); - } - - if (dimensions.Length == 2) - { - return new Point(dimensions[0], dimensions[1]); - } - - return null; - } - - /// - /// Returns the correct for the given string. - /// - /// - /// The input string containing the value to parse. - /// - /// - /// The correct - /// - private int ParseOpacity(string input) - { - int opacity = 100; - Match match = OpacityRegex.Match(input); - if (match.Success) - { - opacity = Math.Abs(CommonParameterParserUtility.ParseIn100Range(match.Value.Split('=')[1])); - } - - return opacity; - } - - /// - /// Returns the correct for the given string. - /// - /// - /// The input string containing the value to parse. - /// - /// - /// The . - /// - private Size ParseSize(string input) - { - Size size = Size.Empty; - Match match = SizeRegex.Match(input); - if (match.Success) - { - int[] dimensions = match.Value.ToPositiveIntegerArray(); - size = new Size(dimensions[0], dimensions[1]); - } - - return size; - } } } diff --git a/src/ImageProcessor.Web/Processors/Pixelate.cs b/src/ImageProcessor.Web/Processors/Pixelate.cs index c4af91036..dae731292 100644 --- a/src/ImageProcessor.Web/Processors/Pixelate.cs +++ b/src/ImageProcessor.Web/Processors/Pixelate.cs @@ -11,13 +11,16 @@ namespace ImageProcessor.Web.Processors { using System; + using System.Collections.Specialized; using System.Drawing; using System.Globalization; using System.Text; using System.Text.RegularExpressions; + using System.Web; using ImageProcessor.Processors; using ImageProcessor.Web.Extensions; + using ImageProcessor.Web.Helpers; /// /// Encapsulates methods to pixelate an image. @@ -27,7 +30,7 @@ namespace ImageProcessor.Web.Processors /// /// The regular expression to search strings for. /// - private static readonly Regex QueryRegex = new Regex(@"(pixelate=|pixelrect=)[^&]+", RegexOptions.Compiled); + private static readonly Regex QueryRegex = new Regex(@"pixelate=[^&]", RegexOptions.Compiled); /// /// The pixel regex. @@ -77,36 +80,19 @@ namespace ImageProcessor.Web.Processors /// public int MatchRegexIndex(string queryString) { - int index = 0; - - // Set the sort order to max to allow filtering. this.SortOrder = int.MaxValue; + Match match = this.RegexPattern.Match(queryString); - // First merge the matches so we can parse . - StringBuilder stringBuilder = new StringBuilder(); - - foreach (Match match in this.RegexPattern.Matches(queryString)) + if (match.Success) { - if (match.Success) - { - if (index == 0) - { - // Set the index on the first instance only. - this.SortOrder = match.Index; - } - - stringBuilder.Append(match.Value); - - index += 1; - } - } + this.SortOrder = match.Index; + NameValueCollection queryCollection = HttpUtility.ParseQueryString(queryString); + int size = QueryParamParser.Instance.ParseValue(queryCollection["pixelate"]); + + Rectangle? rectangle = queryCollection["pixelrect"] != null + ? QueryParamParser.Instance.ParseValue(queryCollection["pixelrect"]) + : (Rectangle?)null; - if (this.SortOrder < int.MaxValue) - { - // Match syntax - string toParse = stringBuilder.ToString(); - int size = this.ParseSize(toParse); - Rectangle? rectangle = this.ParseRectangle(toParse); this.Processor.DynamicParameter = new Tuple(size, rectangle); } diff --git a/src/ImageProcessor.Web/Processors/Quality.cs b/src/ImageProcessor.Web/Processors/Quality.cs index b392aecb5..0a898aa52 100644 --- a/src/ImageProcessor.Web/Processors/Quality.cs +++ b/src/ImageProcessor.Web/Processors/Quality.cs @@ -10,8 +10,11 @@ namespace ImageProcessor.Web.Processors { - using System; + using System.Collections.Specialized; using System.Text.RegularExpressions; + using System.Web; + + using ImageProcessor.Imaging.Helpers; using ImageProcessor.Processors; using ImageProcessor.Web.Helpers; @@ -23,7 +26,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=\d+", RegexOptions.Compiled); /// /// Initializes a new instance of the class. @@ -63,25 +66,16 @@ namespace ImageProcessor.Web.Processors /// 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)) + Match match = this.RegexPattern.Match(queryString); + if (match.Success) { - if (match.Success) - { - if (index == 0) - { - // Set the index on the first instance only. - this.SortOrder = match.Index; - int percentage = Math.Abs(CommonParameterParserUtility.ParseIn100Range(match.Value)); - this.Processor.DynamicParameter = percentage; - } - - index += 1; - } + this.SortOrder = match.Index; + NameValueCollection queryCollection = HttpUtility.ParseQueryString(queryString); + int percentage = QueryParamParser.Instance.ParseValue(queryCollection["quality"]); + percentage = ImageMaths.Clamp(percentage, 0, 100); + this.Processor.DynamicParameter = percentage; } return this.SortOrder; diff --git a/src/ImageProcessor.Web/Processors/ReplaceColor.cs b/src/ImageProcessor.Web/Processors/ReplaceColor.cs index 940a50ad3..254f985a4 100644 --- a/src/ImageProcessor.Web/Processors/ReplaceColor.cs +++ b/src/ImageProcessor.Web/Processors/ReplaceColor.cs @@ -11,13 +11,12 @@ namespace ImageProcessor.Web.Processors { using System; - using System.Collections.Generic; + using System.Collections.Specialized; using System.Drawing; - using System.Globalization; - using System.Linq; - using System.Text; using System.Text.RegularExpressions; + using System.Web; + using ImageProcessor.Imaging.Helpers; using ImageProcessor.Processors; using ImageProcessor.Web.Helpers; @@ -29,17 +28,7 @@ namespace ImageProcessor.Web.Processors /// /// The regular expression to search strings for. /// - private static readonly Regex QueryRegex = new Regex(@"(replace=|fuzziness=)[^&]+", RegexOptions.Compiled); - - /// - /// The replace regex. - /// - private static readonly Regex ReplaceRegex = new Regex(@"replace=[^&]+", RegexOptions.Compiled); - - /// - /// The fuzz regex. - /// - private static readonly Regex FuzzRegex = new Regex(@"fuzziness=\d+", RegexOptions.Compiled); + private static readonly Regex QueryRegex = new Regex(@"replace=[^&]", RegexOptions.Compiled); /// /// Initializes a new instance of the class. @@ -79,84 +68,21 @@ namespace ImageProcessor.Web.Processors /// public int MatchRegexIndex(string queryString) { - int index = 0; - - // Set the sort order to max to allow filtering. this.SortOrder = int.MaxValue; + Match match = this.RegexPattern.Match(queryString); - // First merge the matches so we can parse . - StringBuilder stringBuilder = new StringBuilder(); - - foreach (Match match in this.RegexPattern.Matches(queryString)) + if (match.Success) { - if (match.Success) - { - if (index == 0) - { - // Set the index on the first instance only. - this.SortOrder = match.Index; - } + this.SortOrder = match.Index; + NameValueCollection queryCollection = HttpUtility.ParseQueryString(queryString); + Color[] colors = QueryParamParser.Instance.ParseValue(queryCollection["replace"]); + int fuzziness = QueryParamParser.Instance.ParseValue(queryCollection["fuzziness"]); - stringBuilder.Append(match.Value); - - index += 1; - } - } - - if (this.SortOrder < int.MaxValue) - { - // Match syntax - string toParse = stringBuilder.ToString(); - Color[] colors = this.ParseColor(toParse); - int fuzziness = this.ParseFuzziness(toParse); + fuzziness = ImageMaths.Clamp(fuzziness, 0, 128); this.Processor.DynamicParameter = new Tuple(colors[0], colors[1], fuzziness); } return this.SortOrder; } - - /// - /// Returns the angle to alter the hue. - /// - /// - /// The input containing the value to parse. - /// - /// - /// The representing the angle. - /// - public Color[] ParseColor(string input) - { - IEnumerable colors = Enumerable.Empty(); - Match match = ReplaceRegex.Match(input); - if (match.Success) - { - string[] colorQuery = match.Value.Split('=')[1].Split(new[] { "],[" }, StringSplitOptions.None); - colors = colorQuery.Select(s => CommonParameterParserUtility.ParseColor(s.Replace("[", string.Empty).Replace("]", string.Empty))); - } - - return colors.ToArray(); - } - - /// - /// Returns the angle to alter the hue. - /// - /// - /// The input containing the value to parse. - /// - /// - /// The representing the angle. - /// - public int ParseFuzziness(string input) - { - int fuzziness = 0; - - Match match = FuzzRegex.Match(input); - if (match.Success) - { - fuzziness = int.Parse(match.Value.Split('=')[1], CultureInfo.InvariantCulture); - } - - return Math.Max(0, Math.Min(128, fuzziness)); - } } } diff --git a/src/ImageProcessor/Common/Helpers/TypeFinder.cs b/src/ImageProcessor/Common/Helpers/TypeFinder.cs index bebd004f3..70257b5f0 100644 --- a/src/ImageProcessor/Common/Helpers/TypeFinder.cs +++ b/src/ImageProcessor/Common/Helpers/TypeFinder.cs @@ -59,21 +59,18 @@ namespace ImageProcessor.Common.Helpers { "mscorlib,", "System.", "Antlr3.", "Autofac.", "Autofac,", "Castle.", "ClientDependency.", - "DataAnnotationsExtensions.", - "DataAnnotationsExtensions,", "Dynamic,", + "DataAnnotationsExtensions.", "Dynamic,", "HtmlDiff,", "Iesi.Collections,", "log4net,", "Microsoft.", "Newtonsoft.", "NHibernate.", "NHibernate,", "NuGet.", "RouteDebugger,", - "SqlCE4Umbraco,", "umbraco.datalayer,", - "umbraco.interfaces,", - "umbraco.webservices", "Lucene.", "Examine,", + "SqlCE4Umbraco,", "umbraco.", + "Lucene.", "Examine,", "AutoMapper.", "Examine.", "ServiceStack.", "MySql.", "HtmlAgilityPack.", "TidyNet.", "ICSharpCode.", "CookComputing.", - "AutoMapper,", "AutoMapper.", "AzureDirectory,", "itextsharp,", "UrlRewritingNet.", "HtmlAgilityPack,", - "MiniProfiler,", "Moq,", "nunit.framework,", + "MiniProfiler,", "Moq,", "nunit.", "TidyNet,", "WebDriver," }; @@ -97,8 +94,8 @@ namespace ImageProcessor.Common.Helpers /// loaded in the CLR, not all assemblies. /// See these threads: /// - /// - /// + /// + /// /// /// /// The . @@ -282,7 +279,7 @@ namespace ImageProcessor.Common.Helpers return GetAllAssemblies() .Where(x => !excludeFromResults.Contains(x) && !x.GlobalAssemblyCache - && !exclusionFilter.Any(f => x.FullName.StartsWith(f))); + && !exclusionFilter.Any(f => x.FullName.StartsWith(f, StringComparison.OrdinalIgnoreCase))); } } } diff --git a/src/ImageProcessor/Imaging/AnchorPosition.cs b/src/ImageProcessor/Imaging/AnchorPosition.cs index cb0dd56ae..49362485e 100644 --- a/src/ImageProcessor/Imaging/AnchorPosition.cs +++ b/src/ImageProcessor/Imaging/AnchorPosition.cs @@ -16,14 +16,14 @@ namespace ImageProcessor.Imaging public enum AnchorPosition { /// - /// Anchors the position of the image to the top of it's bounding container. + /// Anchors the position of the image to the center of it's bounding container. /// - Top, + Center, /// - /// Anchors the position of the image to the center of it's bounding container. + /// Anchors the position of the image to the top of it's bounding container. /// - Center, + Top, /// /// Anchors the position of the image to the bottom of it's bounding container. diff --git a/src/ImageProcessor/Processors/Mask.cs b/src/ImageProcessor/Processors/Mask.cs index 86f990a5f..82dad35b7 100644 --- a/src/ImageProcessor/Processors/Mask.cs +++ b/src/ImageProcessor/Processors/Mask.cs @@ -74,7 +74,7 @@ namespace ImageProcessor.Processors int height = image.Height; Tuple parameters = this.DynamicParameter; mask = new Bitmap(parameters.Item1); - Point? position = parameters.Item2.HasValue ? parameters.Item2 : null; + Point? position = parameters.Item2; if (mask.Size != image.Size) { diff --git a/src/ImageProcessor/Processors/ReplaceColor.cs b/src/ImageProcessor/Processors/ReplaceColor.cs index a6f7426f6..dad33192b 100644 --- a/src/ImageProcessor/Processors/ReplaceColor.cs +++ b/src/ImageProcessor/Processors/ReplaceColor.cs @@ -87,13 +87,11 @@ namespace ImageProcessor.Processors using (FastBitmap fastBitmap = new FastBitmap(newImage)) { - //Parallel.For( - // 0, - // height, - // y => - // { - for (int y = 0; y < height; y++) - { + Parallel.For( + 0, + height, + y => + { for (int x = 0; x < width; x++) { // Get the pixel color. @@ -126,7 +124,7 @@ namespace ImageProcessor.Processors } } } - }//); + }); } image.Dispose();