mirror of https://github.com/SixLabors/ImageSharp
34 changed files with 783 additions and 602 deletions
@ -0,0 +1,40 @@ |
|||||
|
<processing preserveExifMetaData="false"> |
||||
|
<presets> |
||||
|
</presets> |
||||
|
<plugins autoLoadPlugins="true"> |
||||
|
<plugin name="Alpha" type="ImageProcessor.Web.Processors.Alpha, ImageProcessor.Web"/> |
||||
|
<plugin name="Brightness" type="ImageProcessor.Web.Processors.Brightness, ImageProcessor.Web"/> |
||||
|
<plugin name="Contrast" type="ImageProcessor.Web.Processors.Contrast, ImageProcessor.Web"/> |
||||
|
<plugin name="Crop" type="ImageProcessor.Web.Processors.Crop, ImageProcessor.Web"/> |
||||
|
<plugin name="Filter" type="ImageProcessor.Web.Processors.Filter, ImageProcessor.Web"/> |
||||
|
<plugin name="Flip" type="ImageProcessor.Web.Processors.Flip, ImageProcessor.Web"/> |
||||
|
<plugin name="Format" type="ImageProcessor.Web.Processors.Format, ImageProcessor.Web"/> |
||||
|
<plugin name="GaussianBlur" type="ImageProcessor.Web.Processors.GaussianBlur, ImageProcessor.Web"> |
||||
|
<settings> |
||||
|
<setting key="MaxSize" value="22"/> |
||||
|
<setting key="MaxSigma" value="5.1"/> |
||||
|
<setting key="MaxThreshold" value="100"/> |
||||
|
</settings> |
||||
|
</plugin> |
||||
|
<plugin name="GaussianSharpen" type="ImageProcessor.Web.Processors.GaussianSharpen, ImageProcessor.Web"> |
||||
|
<settings> |
||||
|
<setting key="MaxSize" value="22"/> |
||||
|
<setting key="MaxSigma" value="5.1"/> |
||||
|
<setting key="MaxThreshold" value="100"/> |
||||
|
</settings> |
||||
|
</plugin> |
||||
|
<plugin name="Quality" type="ImageProcessor.Web.Processors.Quality, ImageProcessor.Web"/> |
||||
|
<plugin name="Resize" type="ImageProcessor.Web.Processors.Resize, ImageProcessor.Web"> |
||||
|
<settings> |
||||
|
<setting key="MaxWidth" value="5000"/> |
||||
|
<setting key="MaxHeight" value="5000"/> |
||||
|
</settings> |
||||
|
</plugin> |
||||
|
<plugin name="Rotate" type="ImageProcessor.Web.Processors.Rotate, ImageProcessor.Web"/> |
||||
|
<plugin name="RoundedCorners" type="ImageProcessor.Web.Processors.RoundedCorners, ImageProcessor.Web"/> |
||||
|
<plugin name="Saturation" type="ImageProcessor.Web.Processors.Saturation, ImageProcessor.Web"/> |
||||
|
<plugin name="Tint" type="ImageProcessor.Web.Processors.Tint, ImageProcessor.Web"/> |
||||
|
<plugin name="Vignette" type="ImageProcessor.Web.Processors.Vignette, ImageProcessor.Web"/> |
||||
|
<plugin name="Watermark" type="ImageProcessor.Web.Processors.Watermark, ImageProcessor.Web"/> |
||||
|
</plugins> |
||||
|
</processing> |
||||
@ -0,0 +1,80 @@ |
|||||
|
namespace ImageProcessor.Web.Processors |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Text.RegularExpressions; |
||||
|
using ImageProcessor.Processors; |
||||
|
using ImageProcessor.Web.Helpers; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Encapsulates methods to change the alpha component of the image to effect its transparency.
|
||||
|
/// </summary>
|
||||
|
public class Alpha : IWebGraphicsProcessor |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The regular expression to search strings for.
|
||||
|
/// </summary>
|
||||
|
private static readonly Regex QueryRegex = new Regex(@"alpha=[^&|,]*", RegexOptions.Compiled); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="Alpha"/> class.
|
||||
|
/// </summary>
|
||||
|
public Alpha() |
||||
|
{ |
||||
|
this.Processor = new ImageProcessor.Processors.Alpha(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the regular expression to search strings for.
|
||||
|
/// </summary>
|
||||
|
public Regex RegexPattern |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
return QueryRegex; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the order in which this processor is to be used in a chain.
|
||||
|
/// </summary>
|
||||
|
public int SortOrder { get; private set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the associated graphics processor.
|
||||
|
/// </summary>
|
||||
|
public IGraphicsProcessor Processor { get; private set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The position in the original string where the first character of the captured substring was found.
|
||||
|
/// </summary>
|
||||
|
/// <param name="queryString">The query string to search.</param>
|
||||
|
/// <returns>
|
||||
|
/// The zero-based starting position in the original string where the captured substring was found.
|
||||
|
/// </returns>
|
||||
|
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; |
||||
|
int percentage = Math.Abs(CommonParameterParserUtility.ParseIn100Range(match.Value)); |
||||
|
this.Processor.DynamicParameter = percentage; |
||||
|
} |
||||
|
|
||||
|
index += 1; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return this.SortOrder; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,89 @@ |
|||||
|
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
// <copyright file="Brightness.cs" company="James South">
|
||||
|
// Copyright (c) James South.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
// <summary>
|
||||
|
// Encapsulates methods to change the brightness component of the image.
|
||||
|
// </summary>
|
||||
|
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
|
||||
|
namespace ImageProcessor.Web.Processors |
||||
|
{ |
||||
|
using System.Text.RegularExpressions; |
||||
|
using ImageProcessor.Processors; |
||||
|
using ImageProcessor.Web.Helpers; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Encapsulates methods to change the brightness component of the image.
|
||||
|
/// </summary>
|
||||
|
public class Brightness : IWebGraphicsProcessor |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The regular expression to search strings for.
|
||||
|
/// </summary>
|
||||
|
private static readonly Regex QueryRegex = new Regex(@"brightness=[^&|,]*", RegexOptions.Compiled); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="Brightness"/> class.
|
||||
|
/// </summary>
|
||||
|
public Brightness() |
||||
|
{ |
||||
|
this.Processor = new ImageProcessor.Processors.Brightness(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the regular expression to search strings for.
|
||||
|
/// </summary>
|
||||
|
public Regex RegexPattern |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
return QueryRegex; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the order in which this processor is to be used in a chain.
|
||||
|
/// </summary>
|
||||
|
public int SortOrder { get; private set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the associated graphics processor.
|
||||
|
/// </summary>
|
||||
|
public IGraphicsProcessor Processor { get; private set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The position in the original string where the first character of the captured substring was found.
|
||||
|
/// </summary>
|
||||
|
/// <param name="queryString">The query string to search.</param>
|
||||
|
/// <returns>
|
||||
|
/// The zero-based starting position in the original string where the captured substring was found.
|
||||
|
/// </returns>
|
||||
|
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; |
||||
|
int percentage = CommonParameterParserUtility.ParseIn100Range(match.Value); |
||||
|
this.Processor.DynamicParameter = percentage; |
||||
|
} |
||||
|
|
||||
|
index += 1; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return this.SortOrder; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,89 @@ |
|||||
|
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
// <copyright file="Contrast.cs" company="James South">
|
||||
|
// Copyright (c) James South.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
// <summary>
|
||||
|
// Encapsulates methods to change the contrast component of the image.
|
||||
|
// </summary>
|
||||
|
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
|
||||
|
namespace ImageProcessor.Web.Processors |
||||
|
{ |
||||
|
using System.Text.RegularExpressions; |
||||
|
using ImageProcessor.Processors; |
||||
|
using ImageProcessor.Web.Helpers; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Encapsulates methods to change the contrast component of the image.
|
||||
|
/// </summary>
|
||||
|
public class Contrast : IWebGraphicsProcessor |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The regular expression to search strings for.
|
||||
|
/// </summary>
|
||||
|
private static readonly Regex QueryRegex = new Regex(@"contrast=[^&|,]*", RegexOptions.Compiled); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="Contrast"/> class.
|
||||
|
/// </summary>
|
||||
|
public Contrast() |
||||
|
{ |
||||
|
this.Processor = new ImageProcessor.Processors.Contrast(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the regular expression to search strings for.
|
||||
|
/// </summary>
|
||||
|
public Regex RegexPattern |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
return QueryRegex; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the order in which this processor is to be used in a chain.
|
||||
|
/// </summary>
|
||||
|
public int SortOrder { get; private set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the associated graphics processor.
|
||||
|
/// </summary>
|
||||
|
public IGraphicsProcessor Processor { get; private set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The position in the original string where the first character of the captured substring was found.
|
||||
|
/// </summary>
|
||||
|
/// <param name="queryString">The query string to search.</param>
|
||||
|
/// <returns>
|
||||
|
/// The zero-based starting position in the original string where the captured substring was found.
|
||||
|
/// </returns>
|
||||
|
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; |
||||
|
int percentage = CommonParameterParserUtility.ParseIn100Range(match.Value); |
||||
|
this.Processor.DynamicParameter = percentage; |
||||
|
} |
||||
|
|
||||
|
index += 1; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return this.SortOrder; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,166 @@ |
|||||
|
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
// <copyright file="Crop.cs" company="James South">
|
||||
|
// Copyright (c) James South.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
// <summary>
|
||||
|
// Crops an image to the given directions.
|
||||
|
// </summary>
|
||||
|
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
|
||||
|
namespace ImageProcessor.Web.Processors |
||||
|
{ |
||||
|
using System.Text; |
||||
|
using System.Text.RegularExpressions; |
||||
|
using ImageProcessor.Core.Common.Extensions; |
||||
|
using ImageProcessor.Imaging; |
||||
|
using ImageProcessor.Processors; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Crops an image to the given directions.
|
||||
|
/// </summary>
|
||||
|
public class Crop : IWebGraphicsProcessor |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The regular expression to search strings for.
|
||||
|
/// <see cref="http://stackoverflow.com/a/6400969/427899"/>
|
||||
|
/// </summary>
|
||||
|
private static readonly Regex QueryRegex = new Regex(@"(crop=|cropmode=)[^&]*", RegexOptions.Compiled); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The coordinate regex.
|
||||
|
/// </summary>
|
||||
|
private static readonly Regex CoordinateRegex = new Regex(@"crop=\d+(.\d+)?[,-]\d+(.\d+)?[,-]\d+(.\d+)?[,-]\d+(.\d+)?", RegexOptions.Compiled); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The mode regex.
|
||||
|
/// </summary>
|
||||
|
private static readonly Regex ModeRegex = new Regex(@"cropmode=(pixels|percent)", RegexOptions.Compiled); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="Crop"/> class.
|
||||
|
/// </summary>
|
||||
|
public Crop() |
||||
|
{ |
||||
|
this.Processor = new ImageProcessor.Processors.Crop(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the regular expression to search strings for.
|
||||
|
/// </summary>
|
||||
|
public Regex RegexPattern |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
return QueryRegex; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the order in which this processor is to be used in a chain.
|
||||
|
/// </summary>
|
||||
|
public int SortOrder { get; private set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the associated graphics processor.
|
||||
|
/// </summary>
|
||||
|
public IGraphicsProcessor Processor { get; private set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The position in the original string where the first character of the captured substring was found.
|
||||
|
/// </summary>
|
||||
|
/// <param name="queryString">The query string to search.</param>
|
||||
|
/// <returns>
|
||||
|
/// The zero-based starting position in the original string where the captured substring was found.
|
||||
|
/// </returns>
|
||||
|
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(); |
||||
|
|
||||
|
float[] coordinates = this.ParseCoordinates(toParse); |
||||
|
CropMode cropMode = this.ParseMode(toParse); |
||||
|
|
||||
|
CropLayer cropLayer = new CropLayer(coordinates[0], coordinates[1], coordinates[2], coordinates[3], cropMode); |
||||
|
this.Processor.DynamicParameter = cropLayer; |
||||
|
} |
||||
|
|
||||
|
return this.SortOrder; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns the correct <see cref="CropMode"/> for the given string.
|
||||
|
/// </summary>
|
||||
|
/// <param name="input">
|
||||
|
/// The input string containing the value to parse.
|
||||
|
/// </param>
|
||||
|
/// <returns>
|
||||
|
/// The correct <see cref="CropMode"/>.
|
||||
|
/// </returns>
|
||||
|
private CropMode ParseMode(string input) |
||||
|
{ |
||||
|
foreach (Match match in ModeRegex.Matches(input)) |
||||
|
{ |
||||
|
// Split on =
|
||||
|
string mode = match.Value.Split('=')[1]; |
||||
|
|
||||
|
switch (mode) |
||||
|
{ |
||||
|
case "percent": |
||||
|
return CropMode.Percentage; |
||||
|
case "pixels": |
||||
|
return CropMode.Pixels; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return CropMode.Pixels; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns the correct <see cref="CropMode"/> for the given string.
|
||||
|
/// </summary>
|
||||
|
/// <param name="input">
|
||||
|
/// The input string containing the value to parse.
|
||||
|
/// </param>
|
||||
|
/// <returns>
|
||||
|
/// The correct <see cref="CropMode"/>.
|
||||
|
/// </returns>
|
||||
|
private float[] ParseCoordinates(string input) |
||||
|
{ |
||||
|
float[] floats = { }; |
||||
|
|
||||
|
foreach (Match match in CoordinateRegex.Matches(input)) |
||||
|
{ |
||||
|
floats = match.Value.ToPositiveFloatArray(); |
||||
|
} |
||||
|
|
||||
|
return floats; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,90 @@ |
|||||
|
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
// <copyright file="Quality.cs" company="James South">
|
||||
|
// Copyright (c) James South.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
// <summary>
|
||||
|
// Encapsulates methods to change the quality component of the image.
|
||||
|
// </summary>
|
||||
|
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
|
||||
|
namespace ImageProcessor.Web.Processors |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Text.RegularExpressions; |
||||
|
using ImageProcessor.Processors; |
||||
|
using ImageProcessor.Web.Helpers; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Encapsulates methods to change the quality component of the image.
|
||||
|
/// </summary>
|
||||
|
public class Quality : IWebGraphicsProcessor |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The regular expression to search strings for.
|
||||
|
/// </summary>
|
||||
|
private static readonly Regex QueryRegex = new Regex(@"quality=[^&|,]*", RegexOptions.Compiled); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="Quality"/> class.
|
||||
|
/// </summary>
|
||||
|
public Quality() |
||||
|
{ |
||||
|
this.Processor = new ImageProcessor.Processors.Quality(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the regular expression to search strings for.
|
||||
|
/// </summary>
|
||||
|
public Regex RegexPattern |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
return QueryRegex; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the order in which this processor is to be used in a chain.
|
||||
|
/// </summary>
|
||||
|
public int SortOrder { get; private set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the associated graphics processor.
|
||||
|
/// </summary>
|
||||
|
public IGraphicsProcessor Processor { get; private set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The position in the original string where the first character of the captured substring was found.
|
||||
|
/// </summary>
|
||||
|
/// <param name="queryString">The query string to search.</param>
|
||||
|
/// <returns>
|
||||
|
/// The zero-based starting position in the original string where the captured substring was found.
|
||||
|
/// </returns>
|
||||
|
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; |
||||
|
int percentage = Math.Abs(CommonParameterParserUtility.ParseIn100Range(match.Value)); |
||||
|
this.Processor.DynamicParameter = percentage; |
||||
|
} |
||||
|
|
||||
|
index += 1; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return this.SortOrder; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,92 @@ |
|||||
|
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
// <copyright file="Saturation.cs" company="James South">
|
||||
|
// Copyright (c) James South.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
// <summary>
|
||||
|
// Encapsulates methods to change the saturation component of the image.
|
||||
|
// </summary>
|
||||
|
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
|
||||
|
namespace ImageProcessor.Web.Processors |
||||
|
{ |
||||
|
using System.Text.RegularExpressions; |
||||
|
using ImageProcessor.Processors; |
||||
|
using ImageProcessor.Web.Helpers; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Encapsulates methods to change the saturation component of the image.
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// <see cref="http://www.bobpowell.net/imagesaturation.htm"/>
|
||||
|
/// </remarks>
|
||||
|
public class Saturation : IWebGraphicsProcessor |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The regular expression to search strings for.
|
||||
|
/// </summary>
|
||||
|
private static readonly Regex QueryRegex = new Regex(@"saturation=[^&|,]*", RegexOptions.Compiled); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="Saturation"/> class.
|
||||
|
/// </summary>
|
||||
|
public Saturation() |
||||
|
{ |
||||
|
this.Processor = new ImageProcessor.Processors.Saturation(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the regular expression to search strings for.
|
||||
|
/// </summary>
|
||||
|
public Regex RegexPattern |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
return QueryRegex; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the order in which this processor is to be used in a chain.
|
||||
|
/// </summary>
|
||||
|
public int SortOrder { get; private set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the associated graphics processor.
|
||||
|
/// </summary>
|
||||
|
public IGraphicsProcessor Processor { get; private set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The position in the original string where the first character of the captured substring was found.
|
||||
|
/// </summary>
|
||||
|
/// <param name="queryString">The query string to search.</param>
|
||||
|
/// <returns>
|
||||
|
/// The zero-based starting position in the original string where the captured substring was found.
|
||||
|
/// </returns>
|
||||
|
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; |
||||
|
int percentage = CommonParameterParserUtility.ParseIn100Range(match.Value); |
||||
|
this.Processor.DynamicParameter = percentage; |
||||
|
} |
||||
|
|
||||
|
index += 1; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return this.SortOrder; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue