diff --git a/src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs b/src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs index a6e863860..88f935076 100644 --- a/src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs +++ b/src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs @@ -25,7 +25,7 @@ namespace ImageProcessor.Web.Helpers /// /// The regular expression to search strings for colors. /// - private static readonly Regex ColorRegex = new Regex(@"(bgcolor|color|tint)(=|-)(\d+,\d+,\d+,\d+|([0-9a-fA-F]{3}){1,2})", RegexOptions.Compiled); + private static readonly Regex ColorRegex = new Regex(@"(bgcolor|color|tint|vignette)(=|-)(\d+,\d+,\d+,\d+|([0-9a-fA-F]{3}){1,2})", RegexOptions.Compiled); /// /// The regular expression to search strings for angles. diff --git a/src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj b/src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj index d1d3dfe66..e302a38ff 100644 --- a/src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj +++ b/src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj @@ -77,6 +77,7 @@ + diff --git a/src/ImageProcessor.Web/NET45/Processors/Vignette.cs b/src/ImageProcessor.Web/NET45/Processors/Vignette.cs new file mode 100644 index 000000000..3982859b9 --- /dev/null +++ b/src/ImageProcessor.Web/NET45/Processors/Vignette.cs @@ -0,0 +1,98 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Encapsulates methods with which to add a vignette image effect to an image. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor.Web.Processors +{ + using System.Drawing; + using System.Text.RegularExpressions; + using ImageProcessor.Processors; + using ImageProcessor.Web.Helpers; + + /// + /// Encapsulates methods with which to add a vignette image effect to an image. + /// + public class Vignette : IWebGraphicsProcessor + { + /// + /// The regular expression to search strings for. + /// + private static readonly Regex QueryRegex = new Regex(@"vignette=(true)?[^&]*", RegexOptions.Compiled); + + /// + /// Initializes a new instance of the class. + /// + public Vignette() + { + this.Processor = new ImageProcessor.Processors.Vignette(); + } + + /// + /// 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; + + Color color = CommonParameterParserUtility.ParseColor(match.Value); + if (color.Equals(Color.Transparent)) + { + color = Color.Black; + } + + this.Processor.DynamicParameter = color; + } + + index += 1; + } + } + + return this.SortOrder; + } + } +} \ No newline at end of file diff --git a/src/ImageProcessor/ImageFactory.cs b/src/ImageProcessor/ImageFactory.cs index ee7efe5c1..a9d74ff3f 100644 --- a/src/ImageProcessor/ImageFactory.cs +++ b/src/ImageProcessor/ImageFactory.cs @@ -788,14 +788,23 @@ namespace ImageProcessor /// /// Adds a vignette image effect to the current image. /// + /// + /// The to tint the image with. Defaults to black. + /// /// /// The current instance of the class. /// - public ImageFactory Vignette() + public ImageFactory Vignette(Color? color = null) { if (this.ShouldProcess) { - Vignette vignette = new Vignette(); + Vignette vignette = new Vignette + { + DynamicParameter = color.HasValue && !color.Equals(Color.Transparent) + ? color.Value + : Color.Black + }; + this.CurrentImageFormat.ApplyProcessor(vignette.ProcessImage, this); } diff --git a/src/ImageProcessor/Imaging/Filters/MatrixFilters.cs b/src/ImageProcessor/Imaging/Filters/MatrixFilters.cs index 9c0b91df0..99b7a705b 100644 --- a/src/ImageProcessor/Imaging/Filters/MatrixFilters.cs +++ b/src/ImageProcessor/Imaging/Filters/MatrixFilters.cs @@ -101,7 +101,7 @@ namespace ImageProcessor.Imaging.Filters { get { - return new LomographMatrixFilter(); + return new LoSatchMatrixFilter(); } } diff --git a/src/ImageProcessor/Processors/Vignette.cs b/src/ImageProcessor/Processors/Vignette.cs index 4236078e8..23830aedd 100644 --- a/src/ImageProcessor/Processors/Vignette.cs +++ b/src/ImageProcessor/Processors/Vignette.cs @@ -24,20 +24,11 @@ namespace ImageProcessor.Processors public class Vignette : IGraphicsProcessor { /// - /// The regular expression to search strings for. + /// Initializes a new instance of the class. /// - private static readonly Regex QueryRegex = new Regex(@"vignette=true", RegexOptions.Compiled); - - #region IGraphicsProcessor Members - /// - /// Gets the regular expression to search strings for. - /// - public Regex RegexPattern + public Vignette() { - get - { - return QueryRegex; - } + this.DynamicParameter = Color.Black; } /// @@ -49,15 +40,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. /// @@ -67,41 +49,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; - bool doVignette; - this.DynamicParameter = bool.TryParse(match.Value.Split('=')[1], out doVignette); - } - - index += 1; - } - } - - return this.SortOrder; - } - /// /// Processes the image. /// @@ -139,12 +86,15 @@ namespace ImageProcessor.Processors path.AddEllipse(ellipsebounds); using (PathGradientBrush brush = new PathGradientBrush(path)) { - // Fill a rectangle with an elliptical gradient brush that goes from white to black. - // Change the colour from white to pure transparent black and from black to pure opaque black. - // This has the effect of painting the far corners black and shade less on the way in to the centre. + // Fill a rectangle with an elliptical gradient brush that goes from transparent to opaque. + // This has the effect of painting the far corners with the given color and shade less on the way in to the centre. + Color baseColor = (Color)this.DynamicParameter; + Color centerColor = Color.FromArgb(0, baseColor.R, baseColor.G, baseColor.B); + Color edgeColor = Color.FromArgb(255, baseColor.R, baseColor.G, baseColor.B); + brush.WrapMode = WrapMode.Tile; - brush.CenterColor = Color.FromArgb(0, 0, 0, 0); - brush.SurroundColors = new[] { Color.FromArgb(255, 0, 0, 0) }; + brush.CenterColor = centerColor; + brush.SurroundColors = new[] { edgeColor }; Blend blend = new Blend { @@ -176,6 +126,5 @@ namespace ImageProcessor.Processors return image; } - #endregion } } \ No newline at end of file