From fee7d322fa674293ddc1bcd62b755168ef56eb27 Mon Sep 17 00:00:00 2001 From: JimBobSquarePants Date: Thu, 4 Apr 2013 01:37:50 +0100 Subject: [PATCH] Added Reset, tweaked Gotham and fixed ToArray() bug. Former-commit-id: d09731b9c6777e48004d8ebf7219be9ac5009068 --- .../Config/ImageProcessorConfig.cs | 2 +- .../Helpers/Extensions/StringExtensions.cs | 4 +- src/ImageProcessor/ImageFactory.cs | 63 ++++++++++++++++--- .../Imaging/Filters/ColorMatrixes.cs | 23 ++----- .../Imaging/Filters/ComicMatrixFilter.cs | 13 ++-- .../Imaging/Filters/GothamMatrixFilter.cs | 24 ++++--- src/ImageProcessor/Processors/Alpha.cs | 24 +------ src/ImageProcessor/Processors/Brightness.cs | 26 +------- src/ImageProcessor/Processors/Contrast.cs | 26 +------- src/ImageProcessor/Processors/Crop.cs | 24 +------ src/ImageProcessor/Processors/Filter.cs | 22 ------- src/ImageProcessor/Processors/Flip.cs | 22 ------- src/ImageProcessor/Processors/Format.cs | 22 ------- .../Processors/IGraphicsProcessor.cs | 18 +----- src/ImageProcessor/Processors/Quality.cs | 24 +------ src/ImageProcessor/Processors/Resize.cs | 26 +------- src/ImageProcessor/Processors/Rotate.cs | 22 ------- src/ImageProcessor/Processors/Saturate.cs | 28 +-------- src/ImageProcessor/Processors/Vignette.cs | 22 ------- src/ImageProcessor/Processors/Watermark.cs | 30 ++------- 20 files changed, 106 insertions(+), 359 deletions(-) diff --git a/src/ImageProcessor.Web/Config/ImageProcessorConfig.cs b/src/ImageProcessor.Web/Config/ImageProcessorConfig.cs index dca89893b..6160150d8 100644 --- a/src/ImageProcessor.Web/Config/ImageProcessorConfig.cs +++ b/src/ImageProcessor.Web/Config/ImageProcessorConfig.cs @@ -257,7 +257,7 @@ namespace ImageProcessor.Web.Config // Add the available settings. foreach (IGraphicsProcessor processor in this.GraphicsProcessors) { - processor.Settings = this.GetPluginSettings(processor.Name); + processor.Settings = this.GetPluginSettings(processor.GetType().Name); } } catch (ReflectionTypeLoadException ex) diff --git a/src/ImageProcessor/Helpers/Extensions/StringExtensions.cs b/src/ImageProcessor/Helpers/Extensions/StringExtensions.cs index ec9fa9e0c..002f41929 100644 --- a/src/ImageProcessor/Helpers/Extensions/StringExtensions.cs +++ b/src/ImageProcessor/Helpers/Extensions/StringExtensions.cs @@ -114,11 +114,11 @@ namespace ImageProcessor.Helpers.Extensions /// /// The String instance that this method extends. /// An array of integers scraped from the String. - public static int[] ToIntegerArray(this string expression) + public static int[] ToPositiveIntegerArray(this string expression) { Contract.Requires(!string.IsNullOrWhiteSpace(expression)); - Regex regex = new Regex(@"(-|)\d+", RegexOptions.Compiled); + Regex regex = new Regex(@"\d+", RegexOptions.Compiled); MatchCollection matchCollection = regex.Matches(expression); diff --git a/src/ImageProcessor/ImageFactory.cs b/src/ImageProcessor/ImageFactory.cs index 6644284c9..ea9891d8b 100644 --- a/src/ImageProcessor/ImageFactory.cs +++ b/src/ImageProcessor/ImageFactory.cs @@ -30,6 +30,11 @@ namespace ImageProcessor /// private const int DefaultJpegQuality = 90; + /// + /// The backup image format. + /// + private ImageFormat backupImageFormat; + /// /// A value indicating whether this instance of the given entity has been disposed. /// @@ -117,6 +122,7 @@ namespace ImageProcessor // Set the other properties. this.JpegQuality = DefaultJpegQuality; + this.backupImageFormat = ImageFormat.Jpeg; this.ImageFormat = ImageFormat.Jpeg; this.ShouldProcess = true; @@ -167,7 +173,9 @@ namespace ImageProcessor // Set the other properties. this.JpegQuality = DefaultJpegQuality; - this.ImageFormat = ImageUtils.GetImageFormat(imageName); + ImageFormat imageFormat = ImageUtils.GetImageFormat(imageName); + this.backupImageFormat = imageFormat; + this.ImageFormat = imageFormat; this.ShouldProcess = true; } } @@ -175,6 +183,37 @@ namespace ImageProcessor return this; } + /// + /// Resets the ImageFactory to its original loaded state. + /// + /// + /// The current instance of the class. + /// + public ImageFactory Reset() + { + if (this.ShouldProcess) + { + MemoryStream memoryStream = (MemoryStream)this.Image.Tag; + + // Set our new image as the memorystream value. + Image newImage = Image.FromStream(memoryStream); + + // Store the stream in the image Tag property so we can dispose of it later. + newImage.Tag = memoryStream; + + // Dispose and reassign the image. + this.Image.Dispose(); + this.Image = newImage; + + // Set the other properties. + this.JpegQuality = DefaultJpegQuality; + this.ImageFormat = this.backupImageFormat; + } + + return this; + } + + #region Manipulation /// /// Adds a query-string to the image factory to allow auto-processing of remote files. @@ -441,7 +480,7 @@ namespace ImageProcessor /// /// The current instance of the class. /// - public ImageFactory Saturate(int percentage) + public ImageFactory Saturation(int percentage) { if (this.ShouldProcess) { @@ -451,7 +490,7 @@ namespace ImageProcessor percentage = 0; } - Saturate saturate = new Saturate { DynamicParameter = percentage }; + Saturation saturate = new Saturation { DynamicParameter = percentage }; this.Image = saturate.ProcessImage(this); } @@ -504,7 +543,10 @@ namespace ImageProcessor /// Saves the current image to the specified file path. /// /// The path to save the image to. - public void Save(string filePath) + /// + /// The current instance of the class. + /// + public ImageFactory Save(string filePath) { if (this.ShouldProcess) { @@ -527,9 +569,9 @@ namespace ImageProcessor ImageCodecInfo.GetImageEncoders().FirstOrDefault( ici => ici.MimeType.Equals("image/jpeg", StringComparison.OrdinalIgnoreCase)); -// ReSharper disable AssignNullToNotNullAttribute + // ReSharper disable AssignNullToNotNullAttribute this.Image.Save(filePath, imageCodecInfo, encoderParameters); -// ReSharper restore AssignNullToNotNullAttribute + // ReSharper restore AssignNullToNotNullAttribute } } else @@ -537,6 +579,8 @@ namespace ImageProcessor this.Image.Save(filePath, this.ImageFormat); } } + + return this; } /// @@ -545,7 +589,10 @@ namespace ImageProcessor /// /// The to save the image information to. /// - public void Save(MemoryStream memoryStream) + /// + /// The current instance of the class. + /// + public ImageFactory Save(MemoryStream memoryStream) { if (this.ShouldProcess) { @@ -573,6 +620,8 @@ namespace ImageProcessor this.Image.Save(memoryStream, this.ImageFormat); } } + + return this; } #region IDisposable Members diff --git a/src/ImageProcessor/Imaging/Filters/ColorMatrixes.cs b/src/ImageProcessor/Imaging/Filters/ColorMatrixes.cs index 76288df73..784370ccb 100644 --- a/src/ImageProcessor/Imaging/Filters/ColorMatrixes.cs +++ b/src/ImageProcessor/Imaging/Filters/ColorMatrixes.cs @@ -10,6 +10,7 @@ namespace ImageProcessor.Imaging.Filters #region Using using System; using System.Collections.Generic; + using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; using System.Drawing.Imaging; @@ -80,6 +81,7 @@ namespace ImageProcessor.Imaging.Filters /// /// Gets Lomograph. /// + [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "Reviewed. Suppression is OK here.")] internal static ColorMatrix Lomograph { get @@ -115,25 +117,6 @@ namespace ImageProcessor.Imaging.Filters } } - /// - /// Gets Gotham. - /// - internal static ColorMatrix Gotham - { - get - { - return new ColorMatrix( - new float[][] - { - new float[] { .9f, .9f, .9f, 0, 0 }, - new float[] { .9f, .9f, .9f, 0, 0 }, - new float[] { .9f, .9f, .9f, 0, 0 }, - new float[] { 0, 0, 0, 1, 0 }, - new float[] { -.5f, -.5f, -.45f, 0, 1 } - }); - } - } - /// /// Gets Invert. /// @@ -156,6 +139,7 @@ namespace ImageProcessor.Imaging.Filters /// /// Gets HiSatch. /// + [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "Reviewed. Suppression is OK here.")] internal static ColorMatrix HiSatch { get @@ -175,6 +159,7 @@ namespace ImageProcessor.Imaging.Filters /// /// Gets LoSatch. /// + [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "Reviewed. Suppression is OK here.")] internal static ColorMatrix LoSatch { get diff --git a/src/ImageProcessor/Imaging/Filters/ComicMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/ComicMatrixFilter.cs index c27358758..9864016ec 100644 --- a/src/ImageProcessor/Imaging/Filters/ComicMatrixFilter.cs +++ b/src/ImageProcessor/Imaging/Filters/ComicMatrixFilter.cs @@ -9,9 +9,11 @@ namespace ImageProcessor.Imaging.Filters { #region Using using System; + using System.Diagnostics.CodeAnalysis; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; + using System.Runtime.InteropServices; #endregion /// @@ -20,8 +22,9 @@ namespace ImageProcessor.Imaging.Filters internal class ComicMatrixFilter : IMatrixFilter { /// - /// Enumurates Argb colour channels. + /// Enumerates Argb color channels. /// + [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "Reviewed. Suppression is OK here.")] private enum ChannelArgb { /// @@ -148,6 +151,7 @@ namespace ImageProcessor.Imaging.Filters patternBitmap.Dispose(); } } + return image; } @@ -185,7 +189,7 @@ namespace ImageProcessor.Imaging.Filters byte[] sourceRgbValues = new byte[bytes]; // Copy the RGB values into the array. - System.Runtime.InteropServices.Marshal.Copy(bitmapDataSource.Scan0, sourceRgbValues, 0, bytes); + Marshal.Copy(bitmapDataSource.Scan0, sourceRgbValues, 0, bytes); // Unlockbits the source. source.UnlockBits(bitmapDataSource); @@ -197,7 +201,7 @@ namespace ImageProcessor.Imaging.Filters byte[] destinationRgbValues = new byte[bytes]; // Copy the RGB values into the array. - System.Runtime.InteropServices.Marshal.Copy(bitmapDataDestination.Scan0, destinationRgbValues, 0, bytes); + Marshal.Copy(bitmapDataDestination.Scan0, destinationRgbValues, 0, bytes); int s = (int)sourceChannel; int d = (int)destinationChannel; @@ -210,11 +214,10 @@ namespace ImageProcessor.Imaging.Filters } // Copy the RGB values back to the bitmap - System.Runtime.InteropServices.Marshal.Copy(destinationRgbValues, 0, bitmapDataDestination.Scan0, bytes); + Marshal.Copy(destinationRgbValues, 0, bitmapDataDestination.Scan0, bytes); // Unlock bits the destination. destination.UnlockBits(bitmapDataDestination); } - } } diff --git a/src/ImageProcessor/Imaging/Filters/GothamMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/GothamMatrixFilter.cs index c14788d50..04e0b5528 100644 --- a/src/ImageProcessor/Imaging/Filters/GothamMatrixFilter.cs +++ b/src/ImageProcessor/Imaging/Filters/GothamMatrixFilter.cs @@ -8,13 +8,12 @@ namespace ImageProcessor.Imaging.Filters { #region Using - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; using System.Drawing; - using System.Drawing.Imaging; using System.Drawing.Drawing2D; + using System.Drawing.Imaging; + + using ImageProcessor.Processors; + #endregion /// @@ -27,7 +26,7 @@ namespace ImageProcessor.Imaging.Filters /// public ColorMatrix Matrix { - get { return ColorMatrixes.Gotham; } + get { return ColorMatrixes.GreyScale; } } /// @@ -61,14 +60,14 @@ namespace ImageProcessor.Imaging.Filters // Paint a burgundy rectangle with a transparency of ~30% over the image. // Paint a blue rectangle with a transparency of 20% over the image. - using (SolidBrush brush = new SolidBrush(Color.FromArgb(77, 43, 4, 18))) + using (SolidBrush brush = new SolidBrush(Color.FromArgb(77, 38, 14, 28))) { Region oldClip = graphics.Clip; graphics.Clip = new Region(rectangle); graphics.FillRectangle(brush, rectangle); // Fill the blue. - brush.Color = Color.FromArgb(51, 12, 22, 88); + brush.Color = Color.FromArgb(51, 29, 32, 59); graphics.FillRectangle(brush, rectangle); graphics.Clip = oldClip; } @@ -76,6 +75,15 @@ namespace ImageProcessor.Imaging.Filters } } + // Add brightness and contrast to finish the effect. + factory.Image = newImage; + Brightness brightness = new Brightness { DynamicParameter = 5 }; + newImage = (Bitmap)brightness.ProcessImage(factory); + + factory.Image = newImage; + Contrast contrast = new Contrast { DynamicParameter = 85 }; + newImage = (Bitmap)contrast.ProcessImage(factory); + // Reassign the image. image.Dispose(); image = newImage; diff --git a/src/ImageProcessor/Processors/Alpha.cs b/src/ImageProcessor/Processors/Alpha.cs index 2d9a0e834..2648a0b8e 100644 --- a/src/ImageProcessor/Processors/Alpha.cs +++ b/src/ImageProcessor/Processors/Alpha.cs @@ -27,28 +27,6 @@ namespace ImageProcessor.Processors private static readonly Regex QueryRegex = new Regex(@"alpha=(?:100|[1-9]?[0-9])", RegexOptions.Compiled); #region IGraphicsProcessor Members - /// - /// Gets the name. - /// - public string Name - { - get - { - return "Alpha"; - } - } - - /// - /// Gets the description. - /// - public string Description - { - get - { - return "Changes the alpha component of the image to effect its transparency."; - } - } - /// /// Gets the regular expression to search strings for. /// @@ -111,7 +89,7 @@ namespace ImageProcessor.Processors { // Set the index on the first instance only. this.SortOrder = match.Index; - int percentage = match.Value.ToIntegerArray()[0]; + int percentage = int.Parse(match.Value.Split('=')[1]); this.DynamicParameter = percentage; } diff --git a/src/ImageProcessor/Processors/Brightness.cs b/src/ImageProcessor/Processors/Brightness.cs index 676e819bb..13f514725 100644 --- a/src/ImageProcessor/Processors/Brightness.cs +++ b/src/ImageProcessor/Processors/Brightness.cs @@ -24,31 +24,9 @@ namespace ImageProcessor.Processors /// The regular expression to search strings for. /// /// - private static readonly Regex QueryRegex = new Regex(@"brightness=(-|)(?:100|[1-9]?[0-9])", RegexOptions.Compiled); + private static readonly Regex QueryRegex = new Regex(@"brightness=(-?(?:100)|-?([1-9]?[0-9]))", RegexOptions.Compiled); #region IGraphicsProcessor Members - /// - /// Gets the name. - /// - public string Name - { - get - { - return "Brightness"; - } - } - - /// - /// Gets the description. - /// - public string Description - { - get - { - return "Changes the the brightness component of the image."; - } - } - /// /// Gets the regular expression to search strings for. /// @@ -111,7 +89,7 @@ namespace ImageProcessor.Processors { // Set the index on the first instance only. this.SortOrder = match.Index; - int percentage = match.Value.ToIntegerArray()[0]; + int percentage = int.Parse(match.Value.Split('=')[1]); this.DynamicParameter = percentage; } diff --git a/src/ImageProcessor/Processors/Contrast.cs b/src/ImageProcessor/Processors/Contrast.cs index 2259cc3a2..15d5e7c8c 100644 --- a/src/ImageProcessor/Processors/Contrast.cs +++ b/src/ImageProcessor/Processors/Contrast.cs @@ -24,31 +24,9 @@ namespace ImageProcessor.Processors /// The regular expression to search strings for. /// /// - private static readonly Regex QueryRegex = new Regex(@"contrast=(-|)(?:100|[1-9]?[0-9])", RegexOptions.Compiled); + private static readonly Regex QueryRegex = new Regex(@"contrast=(-?(?:100)|-?([1-9]?[0-9]))", RegexOptions.Compiled); #region IGraphicsProcessor Members - /// - /// Gets the name. - /// - public string Name - { - get - { - return "Contrast"; - } - } - - /// - /// Gets the description. - /// - public string Description - { - get - { - return "Changes the the contrast component of the image."; - } - } - /// /// Gets the regular expression to search strings for. /// @@ -111,7 +89,7 @@ namespace ImageProcessor.Processors { // Set the index on the first instance only. this.SortOrder = match.Index; - int percentage = match.Value.ToIntegerArray()[0]; + int percentage = int.Parse(match.Value.Split('=')[1]); this.DynamicParameter = percentage; } diff --git a/src/ImageProcessor/Processors/Crop.cs b/src/ImageProcessor/Processors/Crop.cs index f3784e85d..0c2989a34 100644 --- a/src/ImageProcessor/Processors/Crop.cs +++ b/src/ImageProcessor/Processors/Crop.cs @@ -28,28 +28,6 @@ namespace ImageProcessor.Processors private static readonly Regex QueryRegex = new Regex(@"crop=\d+-\d+-\d+-\d+", RegexOptions.Compiled); #region IGraphicsProcessor Members - /// - /// Gets the name. - /// - public string Name - { - get - { - return "Crop"; - } - } - - /// - /// Gets the description. - /// - public string Description - { - get - { - return "Crops an image to the given dimensions."; - } - } - /// /// Gets the regular expression to search strings for. /// @@ -112,7 +90,7 @@ namespace ImageProcessor.Processors { // Set the index on the first instance only. this.SortOrder = match.Index; - int[] coordinates = match.Value.ToIntegerArray(); + int[] coordinates = match.Value.ToPositiveIntegerArray(); int x = coordinates[0]; int y = coordinates[1]; diff --git a/src/ImageProcessor/Processors/Filter.cs b/src/ImageProcessor/Processors/Filter.cs index 7331afb7b..67a96497a 100644 --- a/src/ImageProcessor/Processors/Filter.cs +++ b/src/ImageProcessor/Processors/Filter.cs @@ -26,28 +26,6 @@ namespace ImageProcessor.Processors private static readonly Regex QueryRegex = new Regex(@"filter=(lomograph|polaroid|blackwhite|sepia|greyscale|gotham|invert|hisatch|losatch|comic)", RegexOptions.Compiled); #region IGraphicsProcessor Members - /// - /// Gets the name. - /// - public string Name - { - get - { - return "Filter"; - } - } - - /// - /// Gets the description. - /// - public string Description - { - get - { - return "Encapsulates methods with which to add filters to an image. e.g polaroid, lomograph"; - } - } - /// /// Gets the regular expression to search strings for. /// diff --git a/src/ImageProcessor/Processors/Flip.cs b/src/ImageProcessor/Processors/Flip.cs index 4449d090b..c536be017 100644 --- a/src/ImageProcessor/Processors/Flip.cs +++ b/src/ImageProcessor/Processors/Flip.cs @@ -25,28 +25,6 @@ namespace ImageProcessor.Processors private static readonly Regex QueryRegex = new Regex(@"flip=(horizontal|vertical)", RegexOptions.Compiled); #region IGraphicsProcessor Members - /// - /// Gets the name. - /// - public string Name - { - get - { - return "Flip"; - } - } - - /// - /// Gets the description. - /// - public string Description - { - get - { - return "Flips an image either horizontally or vertically."; - } - } - /// /// Gets the regular expression to search strings for. /// diff --git a/src/ImageProcessor/Processors/Format.cs b/src/ImageProcessor/Processors/Format.cs index 4329bd3ba..30b513ed0 100644 --- a/src/ImageProcessor/Processors/Format.cs +++ b/src/ImageProcessor/Processors/Format.cs @@ -25,28 +25,6 @@ namespace ImageProcessor.Processors private static readonly Regex QueryRegex = new Regex(@"format=(jpeg|png|bmp|gif)", RegexOptions.Compiled); #region IGraphicsProcessor Members - /// - /// Gets the name. - /// - public string Name - { - get - { - return "Format"; - } - } - - /// - /// Gets the description. - /// - public string Description - { - get - { - return "Sets the output of the image to a specific format."; - } - } - /// /// Gets the regular expression to search strings for. /// diff --git a/src/ImageProcessor/Processors/IGraphicsProcessor.cs b/src/ImageProcessor/Processors/IGraphicsProcessor.cs index 96c6525d3..9bbaca130 100644 --- a/src/ImageProcessor/Processors/IGraphicsProcessor.cs +++ b/src/ImageProcessor/Processors/IGraphicsProcessor.cs @@ -8,9 +8,7 @@ namespace ImageProcessor.Processors { #region Using - using System.Collections; using System.Collections.Generic; - using System.Collections.Specialized; using System.Drawing; using System.Text.RegularExpressions; #endregion @@ -20,18 +18,7 @@ namespace ImageProcessor.Processors /// public interface IGraphicsProcessor { - #region MetaData - /// - /// Gets the name. - /// - string Name { get; } - - /// - /// Gets the description. - /// - string Description { get; } - #endregion - + #region Properties /// /// Gets the regular expression to search strings for. /// @@ -50,7 +37,8 @@ namespace ImageProcessor.Processors /// /// Gets or sets any additional settings required by the processor. /// - Dictionary Settings { get; set; } + Dictionary Settings { get; set; } + #endregion #region Methods /// diff --git a/src/ImageProcessor/Processors/Quality.cs b/src/ImageProcessor/Processors/Quality.cs index 4f522247e..632eb27f6 100644 --- a/src/ImageProcessor/Processors/Quality.cs +++ b/src/ImageProcessor/Processors/Quality.cs @@ -25,28 +25,6 @@ namespace ImageProcessor.Processors private static readonly Regex QueryRegex = new Regex(@"quality=(?:100|[1-9]?[0-9])", RegexOptions.Compiled); #region IGraphicsProcessor Members - /// - /// Gets the name. - /// - public string Name - { - get - { - return "Quality"; - } - } - - /// - /// Gets the description. - /// - public string Description - { - get - { - return "Sets the the quality output for jpeg images."; - } - } - /// /// Gets the regular expression to search strings for. /// @@ -109,7 +87,7 @@ namespace ImageProcessor.Processors { // Set the index on the first instance only. this.SortOrder = match.Index; - int percentage = match.Value.ToIntegerArray()[0]; + int percentage = int.Parse(match.Value.Split('=')[1]); this.DynamicParameter = percentage; } diff --git a/src/ImageProcessor/Processors/Resize.cs b/src/ImageProcessor/Processors/Resize.cs index 2e5d0c74a..43cc489a4 100644 --- a/src/ImageProcessor/Processors/Resize.cs +++ b/src/ImageProcessor/Processors/Resize.cs @@ -28,28 +28,6 @@ namespace ImageProcessor.Processors private static readonly Regex QueryRegex = new Regex(@"(width|height)=\d+", RegexOptions.Compiled); #region IGraphicsProcessor Members - /// - /// Gets the name. - /// - public string Name - { - get - { - return "Resize"; - } - } - - /// - /// Gets the description. - /// - public string Description - { - get - { - return "Resizes an image to the given dimensions."; - } - } - /// /// Gets the regular expression to search strings for. /// @@ -118,11 +96,11 @@ namespace ImageProcessor.Processors // Match syntax if (match.Value.Contains("width")) { - size.Width = match.Value.ToIntegerArray()[0]; + size.Width = match.Value.ToPositiveIntegerArray()[0]; } else { - size.Height = match.Value.ToIntegerArray()[0]; + size.Height = match.Value.ToPositiveIntegerArray()[0]; } index += 1; diff --git a/src/ImageProcessor/Processors/Rotate.cs b/src/ImageProcessor/Processors/Rotate.cs index 2f04005a4..480085aa5 100644 --- a/src/ImageProcessor/Processors/Rotate.cs +++ b/src/ImageProcessor/Processors/Rotate.cs @@ -37,28 +37,6 @@ namespace ImageProcessor.Processors private static readonly Regex ColorRegex = new Regex(@"bgcolor-([0-9a-fA-F]{3}){1,2}", RegexOptions.Compiled); #region IGraphicsProcessor Members - /// - /// Gets the name. - /// - public string Name - { - get - { - return "Rotate"; - } - } - - /// - /// Gets the description. - /// - public string Description - { - get - { - return "Rotates an image at the given angle."; - } - } - /// /// Gets the regular expression to search strings for. /// diff --git a/src/ImageProcessor/Processors/Saturate.cs b/src/ImageProcessor/Processors/Saturate.cs index c3f566a38..0ef524c89 100644 --- a/src/ImageProcessor/Processors/Saturate.cs +++ b/src/ImageProcessor/Processors/Saturate.cs @@ -21,37 +21,15 @@ namespace ImageProcessor.Processors /// /// /// - public class Saturate : IGraphicsProcessor + public class Saturation : IGraphicsProcessor { /// /// The regular expression to search strings for. /// /// - private static readonly Regex QueryRegex = new Regex(@"saturate=(-|)(?:100|[1-9]?[0-9])", RegexOptions.Compiled); + private static readonly Regex QueryRegex = new Regex(@"saturation=(-?(?:100)|-?([1-9]?[0-9]))", RegexOptions.Compiled); #region IGraphicsProcessor Members - /// - /// Gets the name. - /// - public string Name - { - get - { - return "Saturate"; - } - } - - /// - /// Gets the description. - /// - public string Description - { - get - { - return "Changes the the saturation component of the image."; - } - } - /// /// Gets the regular expression to search strings for. /// @@ -114,7 +92,7 @@ namespace ImageProcessor.Processors { // Set the index on the first instance only. this.SortOrder = match.Index; - int percentage = match.Value.ToIntegerArray()[0]; + int percentage = int.Parse(match.Value.Split('=')[1]); this.DynamicParameter = percentage; } diff --git a/src/ImageProcessor/Processors/Vignette.cs b/src/ImageProcessor/Processors/Vignette.cs index 52c0e48ac..fd9b58cb3 100644 --- a/src/ImageProcessor/Processors/Vignette.cs +++ b/src/ImageProcessor/Processors/Vignette.cs @@ -26,28 +26,6 @@ namespace ImageProcessor.Processors private static readonly Regex QueryRegex = new Regex(@"vignette=true", RegexOptions.Compiled); #region IGraphicsProcessor Members - /// - /// Gets the name. - /// - public string Name - { - get - { - return "Vignette"; - } - } - - /// - /// Gets the description. - /// - public string Description - { - get - { - return "Adds a vignette image effect to the image."; - } - } - /// /// Gets the regular expression to search strings for. /// diff --git a/src/ImageProcessor/Processors/Watermark.cs b/src/ImageProcessor/Processors/Watermark.cs index 9266dd399..f5900fde9 100644 --- a/src/ImageProcessor/Processors/Watermark.cs +++ b/src/ImageProcessor/Processors/Watermark.cs @@ -45,12 +45,12 @@ private static readonly Regex PositionRegex = new Regex(@"position-\d+-\d+", Reg 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 fontsize attribute. +/// 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 fontstyle attribute. +/// 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); @@ -70,28 +70,6 @@ private static readonly Regex OpacityRegex = new Regex(@"opacity-(?:100|[1-9]?[0 private static readonly Regex ShadowRegex = new Regex(@"shadow-true", RegexOptions.Compiled); #region IGraphicsProcessor Members - /// - /// Gets the name. - /// - public string Name - { - get - { - return "Watermark"; - } - } - - /// - /// Gets the description. - /// - public string Description - { - get - { - return "Adds a watermark containing text to the image."; - } - } - /// /// Gets the regular expression to search strings for. /// @@ -333,7 +311,7 @@ private static readonly Regex ShadowRegex = new Regex(@"shadow-true", RegexOptio { foreach (Match match in PositionRegex.Matches(input)) { - int[] position = match.Value.ToIntegerArray(); + int[] position = match.Value.ToPositiveIntegerArray(); if (position != null) { @@ -392,7 +370,7 @@ private static readonly Regex ShadowRegex = new Regex(@"shadow-true", RegexOptio /// Returns the correct for the given string. /// /// - /// The string containing the respective fontstyle. + /// The string containing the respective font style. /// /// /// The correct