diff --git a/src/ImageProcessor.Playground/Program.cs b/src/ImageProcessor.Playground/Program.cs index 403acb323..15c446519 100644 --- a/src/ImageProcessor.Playground/Program.cs +++ b/src/ImageProcessor.Playground/Program.cs @@ -50,7 +50,7 @@ namespace ImageProcessor.PlayGround } Image mask = Image.FromFile(Path.Combine(resolvedPath, "mask2.png")); - IEnumerable files = GetFilesByExtensions(di, ".gif"); + IEnumerable files = GetFilesByExtensions(di, ".jfif"); //IEnumerable files = GetFilesByExtensions(di, ".gif", ".webp", ".bmp", ".jpg", ".png", ".tif"); foreach (FileInfo fileInfo in files) @@ -66,7 +66,7 @@ namespace ImageProcessor.PlayGround { using (ImageFactory imageFactory = new ImageFactory(true)) { - Size size = new Size(270, 260); + Size size = new Size(400, 400); ResizeLayer layer = new ResizeLayer(size, ResizeMode.Max, AnchorPosition.Center, false); //ContentAwareResizeLayer layer = new ContentAwareResizeLayer(size) @@ -85,7 +85,9 @@ namespace ImageProcessor.PlayGround //.BackgroundColor(Color.Cyan) //.ReplaceColor(Color.FromArgb(255, 1, 107, 165), Color.FromArgb(255, 1, 165, 13), 80) //.Resize(size) - .DetectEdges(new SobelEdgeFilter(), true) + .Resize(new ResizeLayer(size, ResizeMode.Max)) + .Resize(new ResizeLayer(size, ResizeMode.Stretch)) + //.DetectEdges(new SobelEdgeFilter(), true) //.DetectEdges(new LaplacianOfGaussianEdgeFilter()) //.EntropyCrop() //.Filter(MatrixFilters.Invert) diff --git a/src/ImageProcessor.Playground/images/input/img_52061.jfif.REMOVED.git-id b/src/ImageProcessor.Playground/images/input/img_52061.jfif.REMOVED.git-id new file mode 100644 index 000000000..d151f319a --- /dev/null +++ b/src/ImageProcessor.Playground/images/input/img_52061.jfif.REMOVED.git-id @@ -0,0 +1 @@ +8725839c23cba63894d1c8646e8cfd87c615c1fc \ 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 11c2fcfbf..a1fed5fbd 100644 --- a/src/ImageProcessor.Web/Configuration/Resources/processing.config +++ b/src/ImageProcessor.Web/Configuration/Resources/processing.config @@ -28,6 +28,7 @@ + diff --git a/src/ImageProcessor.Web/Helpers/CommonParameterParserUtility.cs b/src/ImageProcessor.Web/Helpers/CommonParameterParserUtility.cs index 2280bea4b..44f8c20cd 100644 --- a/src/ImageProcessor.Web/Helpers/CommonParameterParserUtility.cs +++ b/src/ImageProcessor.Web/Helpers/CommonParameterParserUtility.cs @@ -39,7 +39,6 @@ namespace ImageProcessor.Web.Helpers /// /// The regular expression to search strings for angles. /// - //private static readonly Regex AngleRegex = new Regex(@"(rotate|angle)(=|-)(?:3[0-5][0-9]|[12][0-9]{2}|[1-9][0-9]?)", RegexOptions.Compiled); private static readonly Regex AngleRegex = new Regex(@"(rotate|angle)(=|-)(-)?\d+(.?\d+)?", RegexOptions.Compiled); /// @@ -78,8 +77,8 @@ namespace ImageProcessor.Web.Helpers // Split on angle float angle; string value = match.Value; - value = match.Value.ToUpperInvariant().Contains("ANGLE") - ? value.Substring(value.IndexOf("-", System.StringComparison.Ordinal) + 1) + value = match.Value.ToUpperInvariant().Contains("ANGLE") + ? value.Substring(value.IndexOf("-", System.StringComparison.Ordinal) + 1) : match.Value.Split('=')[1]; float.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out angle); diff --git a/src/ImageProcessor.Web/ImageProcessor.Web.csproj b/src/ImageProcessor.Web/ImageProcessor.Web.csproj index f19d4a04d..c8171d4ba 100644 --- a/src/ImageProcessor.Web/ImageProcessor.Web.csproj +++ b/src/ImageProcessor.Web/ImageProcessor.Web.csproj @@ -48,6 +48,7 @@ + diff --git a/src/ImageProcessor.Web/Processors/Crop.cs b/src/ImageProcessor.Web/Processors/Crop.cs index 35c7b47c3..688b66fdd 100644 --- a/src/ImageProcessor.Web/Processors/Crop.cs +++ b/src/ImageProcessor.Web/Processors/Crop.cs @@ -145,13 +145,13 @@ namespace ImageProcessor.Web.Processors } /// - /// Returns the correct for the given string. + /// Returns the crop coordinates for the given string. /// /// /// The input string containing the value to parse. /// /// - /// The correct . + /// The array containing the crop coordinates. /// private float[] ParseCoordinates(string input) { diff --git a/src/ImageProcessor.Web/Processors/Pixelate.cs b/src/ImageProcessor.Web/Processors/Pixelate.cs new file mode 100644 index 000000000..c4af91036 --- /dev/null +++ b/src/ImageProcessor.Web/Processors/Pixelate.cs @@ -0,0 +1,163 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Encapsulates methods to pixelate an image. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor.Web.Processors +{ + using System; + using System.Drawing; + using System.Globalization; + using System.Text; + using System.Text.RegularExpressions; + + using ImageProcessor.Processors; + using ImageProcessor.Web.Extensions; + + /// + /// Encapsulates methods to pixelate an image. + /// + public class Pixelate : IWebGraphicsProcessor + { + /// + /// The regular expression to search strings for. + /// + private static readonly Regex QueryRegex = new Regex(@"(pixelate=|pixelrect=)[^&]+", RegexOptions.Compiled); + + /// + /// The pixel regex. + /// + private static readonly Regex PixelRegex = new Regex(@"pixelate=\d+", RegexOptions.Compiled); + + /// + /// The rectangle regex. + /// + private static readonly Regex RectangleRegex = new Regex(@"pixelrect=\d+,\d+,\d+,\d+", RegexOptions.Compiled); + + /// + /// Initializes a new instance of the class. + /// + public Pixelate() + { + this.Processor = new ImageProcessor.Processors.Pixelate(); + } + + /// + /// 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; + + // First merge the matches so we can parse . + StringBuilder stringBuilder = new StringBuilder(); + + 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; + } + + stringBuilder.Append(match.Value); + + index += 1; + } + } + + 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); + } + + return this.SortOrder; + } + + /// + /// Returns the correct size of pixels. + /// + /// + /// The input containing the value to parse. + /// + /// + /// The representing the pixel size. + /// + public int ParseSize(string input) + { + int size = 0; + + foreach (Match match in PixelRegex.Matches(input)) + { + size = int.Parse(match.Value.Split('=')[1], CultureInfo.InvariantCulture); + } + + return size; + } + + /// + /// Returns the correct for the given string. + /// + /// + /// The input string containing the value to parse. + /// + /// + /// The correct + /// + private Rectangle? ParseRectangle(string input) + { + int[] dimensions = { }; + + foreach (Match match in RectangleRegex.Matches(input)) + { + dimensions = match.Value.ToPositiveIntegerArray(); + } + + if (dimensions.Length == 4) + { + return new Rectangle(dimensions[0], dimensions[1], dimensions[2], dimensions[3]); + } + + return null; + } + } +} diff --git a/src/TestWebsites/MVC/Test_Website_MVC.csproj b/src/TestWebsites/MVC/Test_Website_MVC.csproj index 4260443d6..c195bf9ce 100644 --- a/src/TestWebsites/MVC/Test_Website_MVC.csproj +++ b/src/TestWebsites/MVC/Test_Website_MVC.csproj @@ -47,7 +47,7 @@ ..\..\..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll - ..\..\..\packages\Microsoft.AspNet.Mvc.FixedDisplayModes.1.0.1\lib\net40\Microsoft.Web.Mvc.FixedDisplayModes.dll + ..\..\packages\Microsoft.AspNet.Mvc.FixedDisplayModes.1.0.1\lib\net40\Microsoft.Web.Mvc.FixedDisplayModes.dll ..\..\..\packages\Newtonsoft.Json.5.0.8\lib\net45\Newtonsoft.Json.dll @@ -65,9 +65,9 @@ True ..\..\..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.Helpers.dll - + True - ..\..\..\packages\Microsoft.AspNet.Mvc.4.0.30506.0\lib\net40\System.Web.Mvc.dll + ..\..\packages\Microsoft.AspNet.Mvc.4.0.40804.0\lib\net40\System.Web.Mvc.dll True diff --git a/src/TestWebsites/MVC/Web.config b/src/TestWebsites/MVC/Web.config index e2f38f0a4..9bef44eaf 100644 --- a/src/TestWebsites/MVC/Web.config +++ b/src/TestWebsites/MVC/Web.config @@ -7,15 +7,15 @@ -
-
-
+
+
+
- - - - + + + + @@ -42,15 +42,15 @@ - + - + - + @@ -62,7 +62,16 @@ - + + + + + + + + + + diff --git a/src/TestWebsites/MVC/packages.config b/src/TestWebsites/MVC/packages.config index 43581dac2..4fa29d03a 100644 --- a/src/TestWebsites/MVC/packages.config +++ b/src/TestWebsites/MVC/packages.config @@ -1,6 +1,6 @@  - +