Browse Source

Moar conversions!

Former-commit-id: f812ee5350b737eb4df0bccae42025c44d133065
af/merge-core
James South 12 years ago
parent
commit
b83179d67a
  1. 0
      src/ImageProcessor.Web/NET45/Configuration/ImageCacheSection.cs
  2. 0
      src/ImageProcessor.Web/NET45/Configuration/ImageProcessingSection.cs
  3. 29
      src/ImageProcessor.Web/NET45/Configuration/ImageProcessorConfiguration.cs
  4. 0
      src/ImageProcessor.Web/NET45/Configuration/ImageSecuritySection.cs
  5. 0
      src/ImageProcessor.Web/NET45/Configuration/Resources/cache.config
  6. 0
      src/ImageProcessor.Web/NET45/Configuration/Resources/processing - Copy.config
  7. 40
      src/ImageProcessor.Web/NET45/Configuration/Resources/processing.config
  8. 0
      src/ImageProcessor.Web/NET45/Configuration/Resources/security.config
  9. 29
      src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs
  10. 2
      src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs
  11. 8
      src/ImageProcessor.Web/NET45/ImageFactoryExtensions.cs
  12. 27
      src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj
  13. 80
      src/ImageProcessor.Web/NET45/Processors/Alpha.cs
  14. 2
      src/ImageProcessor.Web/NET45/Processors/BackgroundColor.cs
  15. 89
      src/ImageProcessor.Web/NET45/Processors/Brightness.cs
  16. 89
      src/ImageProcessor.Web/NET45/Processors/Contrast.cs
  17. 166
      src/ImageProcessor.Web/NET45/Processors/Crop.cs
  18. 90
      src/ImageProcessor.Web/NET45/Processors/Quality.cs
  19. 2
      src/ImageProcessor.Web/NET45/Processors/Rotate.cs
  20. 92
      src/ImageProcessor.Web/NET45/Processors/Saturation.cs
  21. 37
      src/ImageProcessor/ImageFactory.cs
  22. 8
      src/ImageProcessor/Imaging/Filters/GothamMatrixFilter.cs
  23. 5
      src/ImageProcessor/Imaging/Filters/LomographMatrixFilter.cs
  24. 2
      src/ImageProcessor/Imaging/Filters/PolaroidMatrixFilter.cs
  25. 2
      src/ImageProcessor/Imaging/Formats/FormatBase.cs
  26. 4
      src/ImageProcessor/Imaging/Formats/GifFormat.cs
  27. 68
      src/ImageProcessor/Processors/Alpha.cs
  28. 98
      src/ImageProcessor/Processors/Brightness.cs
  29. 80
      src/ImageProcessor/Processors/Contrast.cs
  30. 144
      src/ImageProcessor/Processors/Crop.cs
  31. 67
      src/ImageProcessor/Processors/Quality.cs
  32. 75
      src/ImageProcessor/Processors/Saturation.cs
  33. 6
      src/TestWebsites/NET45/Test_Website_NET45/Web.config
  34. 44
      src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config

0
src/ImageProcessor.Web/NET45/Config/ImageCacheSection.cs → src/ImageProcessor.Web/NET45/Configuration/ImageCacheSection.cs

0
src/ImageProcessor.Web/NET45/Config/ImageProcessingSection.cs → src/ImageProcessor.Web/NET45/Configuration/ImageProcessingSection.cs

29
src/ImageProcessor.Web/NET45/Config/ImageProcessorConfiguration.cs → src/ImageProcessor.Web/NET45/Configuration/ImageProcessorConfiguration.cs

@ -1,5 +1,5 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ImageProcessorConfig.cs" company="James South">
// <copyright file="ImageProcessorConfiguration.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -18,6 +18,8 @@ namespace ImageProcessor.Web.Configuration
using System.Reflection;
using System.Web.Compilation;
using ImageProcessor.Processors;
using ImageProcessor.Web.Processors;
#endregion
/// <summary>
@ -64,8 +66,9 @@ namespace ImageProcessor.Web.Configuration
#endregion
#region Constructors
/// <summary>
/// Prevents a default instance of the <see cref="T:ImageProcessor.Web.Config.ImageProcessorConfig"/> class from being created.
/// Prevents a default instance of the <see cref="ImageProcessorConfiguration"/> class from being created.
/// </summary>
private ImageProcessorConfiguration()
{
@ -75,7 +78,7 @@ namespace ImageProcessor.Web.Configuration
#region Properties
/// <summary>
/// Gets the current instance of the <see cref="T:ImageProcessor.Web.Config.ImageProcessorConfig"/> class.
/// Gets the current instance of the <see cref="ImageProcessorConfiguration"/> class.
/// </summary>
public static ImageProcessorConfiguration Instance
{
@ -88,7 +91,7 @@ namespace ImageProcessor.Web.Configuration
/// <summary>
/// Gets the list of available GraphicsProcessors.
/// </summary>
public IList<IGraphicsProcessor> GraphicsProcessors { get; private set; }
public IList<IWebGraphicsProcessor> GraphicsProcessors { get; private set; }
/// <summary>
/// Gets a value indicating whether to preserve exif meta data.
@ -292,7 +295,7 @@ namespace ImageProcessor.Web.Configuration
{
if (GetImageProcessingSection().Plugins.AutoLoadPlugins)
{
Type type = typeof(IGraphicsProcessor);
Type type = typeof(IWebGraphicsProcessor);
try
{
// Build a list of native IGraphicsProcessor instances.
@ -303,12 +306,12 @@ namespace ImageProcessor.Web.Configuration
.ToList();
// Create them and add.
this.GraphicsProcessors = availableTypes.Select(x => (Activator.CreateInstance(x) as IGraphicsProcessor)).ToList();
this.GraphicsProcessors = availableTypes.Select(x => (Activator.CreateInstance(x) as IWebGraphicsProcessor)).ToList();
// Add the available settings.
foreach (IGraphicsProcessor processor in this.GraphicsProcessors)
foreach (IWebGraphicsProcessor webProcessor in this.GraphicsProcessors)
{
processor.Settings = this.GetPluginSettings(processor.GetType().Name);
webProcessor.Processor.Settings = this.GetPluginSettings(webProcessor.GetType().Name);
}
}
catch (ReflectionTypeLoadException)
@ -332,23 +335,23 @@ namespace ImageProcessor.Web.Configuration
private void LoadGraphicsProcessorsFromConfiguration()
{
ImageProcessingSection.PluginElementCollection pluginConfigs = imageProcessingSection.Plugins;
this.GraphicsProcessors = new List<IGraphicsProcessor>();
this.GraphicsProcessors = new List<IWebGraphicsProcessor>();
foreach (ImageProcessingSection.PluginElement pluginConfig in pluginConfigs)
{
Type type = Type.GetType(pluginConfig.Type);
if (type == null)
{
throw new TypeLoadException("Couldn't load IGraphicsProcessor: " + pluginConfig.Type);
throw new TypeLoadException("Couldn't load IWebGraphicsProcessor: " + pluginConfig.Type);
}
this.GraphicsProcessors.Add(Activator.CreateInstance(type) as IGraphicsProcessor);
this.GraphicsProcessors.Add(Activator.CreateInstance(type) as IWebGraphicsProcessor);
}
// Add the available settings.
foreach (IGraphicsProcessor processor in this.GraphicsProcessors)
foreach (IWebGraphicsProcessor webProcessor in this.GraphicsProcessors)
{
processor.Settings = this.GetPluginSettings(processor.GetType().Name);
webProcessor.Processor.Settings = this.GetPluginSettings(webProcessor.GetType().Name);
}
}
#endregion

0
src/ImageProcessor.Web/NET45/Config/ImageSecuritySection.cs → src/ImageProcessor.Web/NET45/Configuration/ImageSecuritySection.cs

0
src/ImageProcessor.Web/NET45/Config/Resources/cache.config → src/ImageProcessor.Web/NET45/Configuration/Resources/cache.config

0
src/ImageProcessor.Web/NET45/Config/Resources/processing.config → src/ImageProcessor.Web/NET45/Configuration/Resources/processing - Copy.config

40
src/ImageProcessor.Web/NET45/Configuration/Resources/processing.config

@ -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
src/ImageProcessor.Web/NET45/Config/Resources/security.config → src/ImageProcessor.Web/NET45/Configuration/Resources/security.config

29
src/ImageProcessor.Web/NET45/Helpers/ParameterParserUtilities.cs → src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs

@ -1,5 +1,5 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ParameterParserUtilities.cs" company="James South">
// <copyright file="CommonParameterParserUtility.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -18,7 +18,7 @@ namespace ImageProcessor.Web.Helpers
/// <summary>
/// Encapsulates methods to correctly parse querystring parameters.
/// </summary>
public static class ParameterParserUtilities
public static class CommonParameterParserUtility
{
/// <summary>
/// The regular expression to search strings for colors.
@ -30,6 +30,11 @@ namespace ImageProcessor.Web.Helpers
/// </summary>
private static readonly Regex AngleRegex = new Regex(@"(rotate|angle)(=|-)(?:3[0-5][0-9]|[12][0-9]{2}|[1-9][0-9]?)", RegexOptions.Compiled);
/// <summary>
/// The regular expression to search strings for values between 1 and 100.
/// </summary>
private static readonly Regex In100RangeRegex = new Regex(@"(-?(?:100)|-?([1-9]?[0-9]))", RegexOptions.Compiled);
/// <summary>
/// Returns the correct <see cref="T:System.Int32"/> containing the angle for the given string.
/// </summary>
@ -86,5 +91,25 @@ namespace ImageProcessor.Web.Helpers
return Color.Transparent;
}
/// <summary>
/// Returns the correct <see cref="T:System.Int32"/> for the given string.
/// </summary>
/// <param name="input">
/// The input string containing the value to parse.
/// </param>
/// <returns>
/// The correct <see cref="T:System.Int32"/> between -100 and 100.
/// </returns>
public static int ParseIn100Range(string input)
{
int value = 0;
foreach (Match match in In100RangeRegex.Matches(input))
{
value = int.Parse(match.Value, CultureInfo.InvariantCulture);
}
return value;
}
}
}

2
src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs

@ -414,7 +414,7 @@ namespace ImageProcessor.Web.HttpModules
.Save(cachedPath);
// Store the response type in the context for later retrieval.
context.Items[CachedResponseTypeKey] = imageFactory.MimeType;
context.Items[CachedResponseTypeKey] = imageFactory.CurrentImageFormat.MimeType;
// Ensure that the LastWriteTime property of the source and cached file match.
Tuple<DateTime, DateTime> creationAndLastWriteDateTimes = await cache.SetCachedLastWriteTimeAsync();

8
src/ImageProcessor.Web/NET45/ImageFactoryExtensions.cs

@ -13,8 +13,8 @@ namespace ImageProcessor.Web
#region Using
using System.Collections.Generic;
using System.Linq;
using ImageProcessor.Processors;
using ImageProcessor.Web.Configuration;
using ImageProcessor.Web.Processors;
#endregion
/// <summary>
@ -45,16 +45,16 @@ namespace ImageProcessor.Web
lock (SyncRoot)
{
// Get a list of all graphics processors that have parsed and matched the query string.
List<IGraphicsProcessor> graphicsProcessors =
List<IWebGraphicsProcessor> graphicsProcessors =
ImageProcessorConfiguration.Instance.GraphicsProcessors
.Where(x => x.MatchRegexIndex(factory.QueryString) != int.MaxValue)
.OrderBy(y => y.SortOrder)
.ToList();
// Loop through and process the image.
foreach (IGraphicsProcessor graphicsProcessor in graphicsProcessors)
foreach (IWebGraphicsProcessor graphicsProcessor in graphicsProcessors)
{
factory.CurrentImageFormat.ApplyProcessor(graphicsProcessor.ProcessImage, factory);
factory.CurrentImageFormat.ApplyProcessor(graphicsProcessor.Processor.ProcessImage, factory);
}
}
}

27
src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj

@ -49,20 +49,26 @@
<Compile Include="Caching\MemCache.cs" />
<Compile Include="Caching\DiskCache.cs" />
<Compile Include="Caching\CacheIndexer.cs" />
<Compile Include="Config\ImageCacheSection.cs" />
<Compile Include="Config\ImageProcessingSection.cs" />
<Compile Include="Config\ImageProcessorConfiguration.cs" />
<Compile Include="Config\ImageSecuritySection.cs" />
<Compile Include="Helpers\ParameterParserUtilities.cs" />
<Compile Include="Configuration\ImageCacheSection.cs" />
<Compile Include="Configuration\ImageProcessingSection.cs" />
<Compile Include="Configuration\ImageProcessorConfiguration.cs" />
<Compile Include="Configuration\ImageSecuritySection.cs" />
<Compile Include="Helpers\CommonParameterParserUtility.cs" />
<Compile Include="Helpers\ResourceHelpers.cs" />
<Compile Include="Helpers\ImageHelpers.cs" />
<Compile Include="Helpers\RemoteFile.cs" />
<Compile Include="Helpers\TaskHelpers.cs" />
<Compile Include="HttpModules\ImageProcessingModule.cs" />
<Compile Include="ImageFactoryExtensions.cs" />
<Compile Include="Processors\Alpha.cs" />
<Compile Include="Processors\BackgroundColor.cs" />
<Compile Include="Processors\Brightness.cs" />
<Compile Include="Processors\Contrast.cs" />
<Compile Include="Processors\Crop.cs" />
<Compile Include="Processors\IWebGraphicsProcessor.cs" />
<Compile Include="Processors\Quality.cs" />
<Compile Include="Processors\Rotate.cs" />
<Compile Include="Processors\Saturation.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
@ -72,13 +78,18 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Config\Resources\cache.config">
<EmbeddedResource Include="Configuration\Resources\cache.config">
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Config\Resources\processing.config">
<EmbeddedResource Include="Configuration\Resources\processing.config">
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Configuration\Resources\security.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Configuration\Resources\processing - Copy.config">
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Config\Resources\security.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />

80
src/ImageProcessor.Web/NET45/Processors/Alpha.cs

@ -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;
}
}
}

2
src/ImageProcessor.Web/NET45/Processors/BackgroundColor.cs

@ -75,7 +75,7 @@ namespace ImageProcessor.Web.Processors
{
// Set the index on the first instance only.
this.SortOrder = match.Index;
this.Processor.DynamicParameter = ParameterParserUtilities.ParseColor(match.Value);
this.Processor.DynamicParameter = CommonParameterParserUtility.ParseColor(match.Value);
}
index += 1;

89
src/ImageProcessor.Web/NET45/Processors/Brightness.cs

@ -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;
}
}
}

89
src/ImageProcessor.Web/NET45/Processors/Contrast.cs

@ -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;
}
}
}

166
src/ImageProcessor.Web/NET45/Processors/Crop.cs

@ -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;
}
}
}

90
src/ImageProcessor.Web/NET45/Processors/Quality.cs

@ -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;
}
}
}

2
src/ImageProcessor.Web/NET45/Processors/Rotate.cs

@ -82,7 +82,7 @@ namespace ImageProcessor.Web.Processors
{
// Set the index on the first instance only.
this.SortOrder = match.Index;
this.Processor.DynamicParameter = ParameterParserUtilities.ParseAngle(match.Value);
this.Processor.DynamicParameter = CommonParameterParserUtility.ParseAngle(match.Value);
}
index += 1;

92
src/ImageProcessor.Web/NET45/Processors/Saturation.cs

@ -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;
}
}
}

37
src/ImageProcessor/ImageFactory.cs

@ -91,11 +91,6 @@ namespace ImageProcessor
#endregion
#region Properties
/// <summary>
/// Gets the local image for manipulation.
/// </summary>
public Image Image { get; private set; }
/// <summary>
/// Gets the path to the local image for manipulation.
/// </summary>
@ -126,6 +121,11 @@ namespace ImageProcessor
/// </summary>
public ConcurrentDictionary<int, PropertyItem> ExifPropertyItems { get; set; }
/// <summary>
/// Gets or sets the local image for manipulation.
/// </summary>
internal Image Image { get; set; }
/// <summary>
/// Gets or sets the original extension.
/// </summary>
@ -254,33 +254,6 @@ namespace ImageProcessor
return this;
}
/// <summary>
/// Updates the specified image. Used by the various IProcessors.
/// </summary>
/// <param name="image">The image.</param>
/// <returns>
/// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
/// </returns>
public ImageFactory Update(Image image)
{
if (this.ShouldProcess)
{
this.Image = image;
// Get the correct image format for the image.
using (MemoryStream stream = new MemoryStream())
{
image.Save(stream, image.RawFormat);
stream.Position = 0;
int quality = this.CurrentImageFormat.Quality;
this.CurrentImageFormat = FormatUtilities.GetFormat(stream);
this.CurrentImageFormat.Quality = quality;
}
}
return this;
}
/// <summary>
/// Resets the current image to its original loaded state.
/// </summary>

8
src/ImageProcessor/Imaging/Filters/GothamMatrixFilter.cs

@ -79,13 +79,13 @@ namespace ImageProcessor.Imaging.Filters
}
// Add brightness and contrast to finish the effect.
factory.Update(newImage);
factory.Image = newImage;
Brightness brightness = new Brightness { DynamicParameter = 5 };
newImage = (Bitmap)brightness.ProcessImage(factory);
newImage = brightness.ProcessImage(factory);
factory.Update(newImage);
factory.Image = newImage;
Contrast contrast = new Contrast { DynamicParameter = 85 };
newImage = (Bitmap)contrast.ProcessImage(factory);
newImage = contrast.ProcessImage(factory);
// Reassign the image.
image.Dispose();

5
src/ImageProcessor/Imaging/Filters/LomographMatrixFilter.cs

@ -50,15 +50,14 @@ namespace ImageProcessor.Imaging.Filters
attributes.SetColorMatrix(this.Matrix);
Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);
graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
}
}
// Add a vignette to finish the effect.
factory.Update(newImage);
factory.Image = newImage;
Vignette vignette = new Vignette();
newImage = (Bitmap)vignette.ProcessImage(factory);
newImage = vignette.ProcessImage(factory);
// Reassign the image.
image.Dispose();

2
src/ImageProcessor/Imaging/Filters/PolaroidMatrixFilter.cs

@ -85,7 +85,7 @@ namespace ImageProcessor.Imaging.Filters
}
// Add a vignette to finish the effect.
factory.Update(newImage);
factory.Image = newImage;
Vignette vignette = new Vignette();
newImage = vignette.ProcessImage(factory);

2
src/ImageProcessor/Imaging/Formats/FormatBase.cs

@ -73,7 +73,7 @@ namespace ImageProcessor.Imaging.Formats
/// <param name="factory">The <see cref="ImageFactory" />.</param>
public virtual void ApplyProcessor(Func<ImageFactory, Image> processor, ImageFactory factory)
{
processor.Invoke(factory);
factory.Image = processor.Invoke(factory);
}
/// <summary>

4
src/ImageProcessor/Imaging/Formats/GifFormat.cs

@ -86,14 +86,14 @@ namespace ImageProcessor.Imaging.Formats
{
foreach (GifFrame frame in imageInfo.GifFrames)
{
factory.Update(frame.Image);
factory.Image = frame.Image;
frame.Image = quantizer.Quantize(processor.Invoke(factory));
encoder.AddFrame(frame);
}
}
stream.Position = 0;
factory.Update(Image.FromStream(stream));
factory.Image = Image.FromStream(stream);
}
else
{

68
src/ImageProcessor/Processors/Alpha.cs

@ -10,37 +10,15 @@
namespace ImageProcessor.Processors
{
#region Using
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.Text.RegularExpressions;
#endregion
/// <summary>
/// Encapsulates methods to change the alpha component of the image to effect its transparency.
/// </summary>
public class Alpha : IGraphicsProcessor
{
/// <summary>
/// The regular expression to search strings for.
/// <see cref="http://stackoverflow.com/a/6400969/427899"/>
/// </summary>
private static readonly Regex QueryRegex = new Regex(@"alpha=(?:100|[1-9]?[0-9])", RegexOptions.Compiled);
#region IGraphicsProcessor Members
/// <summary>
/// Gets the regular expression to search strings for.
/// </summary>
public Regex RegexPattern
{
get
{
return QueryRegex;
}
}
/// <summary>
/// Gets or sets DynamicParameter.
/// </summary>
@ -50,15 +28,6 @@ namespace ImageProcessor.Processors
set;
}
/// <summary>
/// Gets the order in which this processor is to be used in a chain.
/// </summary>
public int SortOrder
{
get;
private set;
}
/// <summary>
/// Gets or sets any additional settings required by the processor.
/// </summary>
@ -68,42 +37,6 @@ namespace ImageProcessor.Processors
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 = int.Parse(match.Value.Split('=')[1], CultureInfo.InvariantCulture);
this.DynamicParameter = percentage;
}
index += 1;
}
}
return this.SortOrder;
}
/// <summary>
/// Processes the image.
/// </summary>
@ -152,6 +85,5 @@ namespace ImageProcessor.Processors
return image;
}
#endregion
}
}

98
src/ImageProcessor/Processors/Brightness.cs

@ -10,37 +10,15 @@
namespace ImageProcessor.Processors
{
#region Using
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.Text.RegularExpressions;
#endregion
/// <summary>
/// Encapsulates methods to change the brightness component of the image.
/// </summary>
public class Brightness : IGraphicsProcessor
{
/// <summary>
/// The regular expression to search strings for.
/// <see cref="http://stackoverflow.com/a/6400969/427899"/>
/// </summary>
private static readonly Regex QueryRegex = new Regex(@"brightness=(-?(?:100)|-?([1-9]?[0-9]))", RegexOptions.Compiled);
#region IGraphicsProcessor Members
/// <summary>
/// Gets the regular expression to search strings for.
/// </summary>
public Regex RegexPattern
{
get
{
return QueryRegex;
}
}
/// <summary>
/// Gets or sets DynamicParameter.
/// </summary>
@ -50,15 +28,6 @@ namespace ImageProcessor.Processors
set;
}
/// <summary>
/// Gets the order in which this processor is to be used in a chain.
/// </summary>
public int SortOrder
{
get;
private set;
}
/// <summary>
/// Gets or sets any additional settings required by the processor.
/// </summary>
@ -68,42 +37,6 @@ namespace ImageProcessor.Processors
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 = int.Parse(match.Value.Split('=')[1], CultureInfo.InvariantCulture);
this.DynamicParameter = percentage;
}
index += 1;
}
}
return this.SortOrder;
}
/// <summary>
/// Processes the image.
/// </summary>
@ -125,16 +58,14 @@ namespace ImageProcessor.Processors
newImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppPArgb);
ColorMatrix colorMatrix = new ColorMatrix(
new float[][]
{
new float[] { 1, 0, 0, 0, 0 },
new float[] { 0, 1, 0, 0, 0 },
new float[] { 0, 0, 1, 0, 0 },
new float[] { 0, 0, 0, 1, 0 },
new float[] { brightnessFactor, brightnessFactor, brightnessFactor, 0, 1 }
});
ColorMatrix colorMatrix =
new ColorMatrix(
new[]
{
new float[] { 1, 0, 0, 0, 0 }, new float[] { 0, 1, 0, 0, 0 },
new float[] { 0, 0, 1, 0, 0 }, new float[] { 0, 0, 0, 1, 0 },
new[] { brightnessFactor, brightnessFactor, brightnessFactor, 0, 1 }
});
using (Graphics graphics = Graphics.FromImage(newImage))
{
@ -142,7 +73,15 @@ namespace ImageProcessor.Processors
{
imageAttributes.SetColorMatrix(colorMatrix);
graphics.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttributes);
graphics.DrawImage(
image,
new Rectangle(0, 0, image.Width, image.Height),
0,
0,
image.Width,
image.Height,
GraphicsUnit.Pixel,
imageAttributes);
image.Dispose();
image = newImage;
@ -159,6 +98,5 @@ namespace ImageProcessor.Processors
return image;
}
#endregion
}
}
}

80
src/ImageProcessor/Processors/Contrast.cs

@ -10,37 +10,15 @@
namespace ImageProcessor.Processors
{
#region Using
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.Text.RegularExpressions;
#endregion
/// <summary>
/// Encapsulates methods to change the contrast component of the image.
/// </summary>
public class Contrast : IGraphicsProcessor
{
/// <summary>
/// The regular expression to search strings for.
/// <see cref="http://stackoverflow.com/a/6400969/427899"/>
/// </summary>
private static readonly Regex QueryRegex = new Regex(@"contrast=(-?(?:100)|-?([1-9]?[0-9]))", RegexOptions.Compiled);
#region IGraphicsProcessor Members
/// <summary>
/// Gets the regular expression to search strings for.
/// </summary>
public Regex RegexPattern
{
get
{
return QueryRegex;
}
}
/// <summary>
/// Gets or sets DynamicParameter.
/// </summary>
@ -50,15 +28,6 @@ namespace ImageProcessor.Processors
set;
}
/// <summary>
/// Gets the order in which this processor is to be used in a chain.
/// </summary>
public int SortOrder
{
get;
private set;
}
/// <summary>
/// Gets or sets any additional settings required by the processor.
/// </summary>
@ -68,42 +37,6 @@ namespace ImageProcessor.Processors
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 = int.Parse(match.Value.Split('=')[1], CultureInfo.InvariantCulture);
this.DynamicParameter = percentage;
}
index += 1;
}
}
return this.SortOrder;
}
/// <summary>
/// Processes the image.
/// </summary>
@ -130,13 +63,13 @@ namespace ImageProcessor.Processors
newImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppPArgb);
ColorMatrix colorMatrix = new ColorMatrix(
new float[][]
new[]
{
new float[] { contrastFactor, 0, 0, 0, 0 },
new float[] { 0, contrastFactor, 0, 0, 0 },
new float[] { 0, 0, contrastFactor, 0, 0 },
new[] { contrastFactor, 0, 0, 0, 0 },
new[] { 0, contrastFactor, 0, 0, 0 },
new[] { 0, 0, contrastFactor, 0, 0 },
new float[] { 0, 0, 0, 1, 0 },
new float[] { factorTransform, factorTransform, factorTransform, 0, 1 }
new[] { factorTransform, factorTransform, factorTransform, 0, 1 }
});
using (Graphics graphics = Graphics.FromImage(newImage))
@ -162,6 +95,5 @@ namespace ImageProcessor.Processors
return image;
}
#endregion
}
}
}

144
src/ImageProcessor/Processors/Crop.cs

@ -15,12 +15,7 @@ namespace ImageProcessor.Processors
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Text;
using System.Text.RegularExpressions;
using ImageProcessor.Core.Common.Extensions;
using ImageProcessor.Imaging;
#endregion
/// <summary>
@ -28,34 +23,6 @@ namespace ImageProcessor.Processors
/// </summary>
public class Crop : IGraphicsProcessor
{
/// <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=\d+(.\d+)?[,-]\d+(.\d+)?[,-]\d+(.\d+)?[,-]\d+(.\d+)?|cropmode=(pixels|percent)", 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);
#region IGraphicsProcessor Members
/// <summary>
/// Gets the regular expression to search strings for.
/// </summary>
public Regex RegexPattern
{
get
{
return QueryRegex;
}
}
/// <summary>
/// Gets or sets DynamicParameter.
/// </summary>
@ -65,15 +32,6 @@ namespace ImageProcessor.Processors
set;
}
/// <summary>
/// Gets the order in which this processor is to be used in a chain.
/// </summary>
public int SortOrder
{
get;
private set;
}
/// <summary>
/// Gets or sets any additional settings required by the processor.
/// </summary>
@ -83,56 +41,6 @@ namespace ImageProcessor.Processors
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.DynamicParameter = cropLayer;
}
return this.SortOrder;
}
/// <summary>
/// Processes the image.
/// </summary>
@ -159,7 +67,7 @@ namespace ImageProcessor.Processors
// Work out the percentages.
float left = cropLayer.Left * sourceWidth;
float top = cropLayer.Top * sourceHeight;
float width = (1 - cropLayer.Left - cropLayer.Right) * sourceWidth;
float width = (1 - cropLayer.Left - cropLayer.Right) * sourceWidth;
float height = (1 - cropLayer.Top - cropLayer.Bottom) * sourceHeight;
rectangleF = new RectangleF(left, top, width, height);
@ -226,55 +134,5 @@ namespace ImageProcessor.Processors
return image;
}
#endregion
/// <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;
}
}
}

67
src/ImageProcessor/Processors/Quality.cs

@ -13,8 +13,6 @@ namespace ImageProcessor.Processors
#region Using
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Text.RegularExpressions;
#endregion
/// <summary>
@ -22,23 +20,6 @@ namespace ImageProcessor.Processors
/// </summary>
public class Quality : IGraphicsProcessor
{
/// <summary>
/// The regular expression to search strings for.
/// </summary>
private static readonly Regex QueryRegex = new Regex(@"quality=(?:100|[1-9]?[0-9])", RegexOptions.Compiled);
#region IGraphicsProcessor Members
/// <summary>
/// Gets the regular expression to search strings for.
/// </summary>
public Regex RegexPattern
{
get
{
return QueryRegex;
}
}
/// <summary>
/// Gets or sets DynamicParameter.
/// </summary>
@ -48,15 +29,6 @@ namespace ImageProcessor.Processors
set;
}
/// <summary>
/// Gets the order in which this processor is to be used in a chain.
/// </summary>
public int SortOrder
{
get;
private set;
}
/// <summary>
/// Gets or sets any additional settings required by the processor.
/// </summary>
@ -66,42 +38,6 @@ namespace ImageProcessor.Processors
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 = int.Parse(match.Value.Split('=')[1], CultureInfo.InvariantCulture);
this.DynamicParameter = percentage;
}
index += 1;
}
}
return this.SortOrder;
}
/// <summary>
/// Processes the image.
/// </summary>
@ -114,11 +50,8 @@ namespace ImageProcessor.Processors
/// </returns>
public Image ProcessImage(ImageFactory factory)
{
// Set the internal property.
factory.CurrentImageFormat.Quality = this.DynamicParameter;
return factory.Image;
}
#endregion
}
}

75
src/ImageProcessor/Processors/Saturation.cs

@ -14,9 +14,6 @@ namespace ImageProcessor.Processors
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.Text.RegularExpressions;
#endregion
/// <summary>
@ -27,24 +24,7 @@ namespace ImageProcessor.Processors
/// </remarks>
public class Saturation : IGraphicsProcessor
{
/// <summary>
/// The regular expression to search strings for.
/// <see cref="http://stackoverflow.com/a/6400969/427899"/>
/// </summary>
private static readonly Regex QueryRegex = new Regex(@"saturation=(-?(?:100)|-?([1-9]?[0-9]))", RegexOptions.Compiled);
#region IGraphicsProcessor Members
/// <summary>
/// Gets the regular expression to search strings for.
/// </summary>
public Regex RegexPattern
{
get
{
return QueryRegex;
}
}
/// <summary>
/// Gets or sets DynamicParameter.
/// </summary>
@ -54,15 +34,6 @@ namespace ImageProcessor.Processors
set;
}
/// <summary>
/// Gets the order in which this processor is to be used in a chain.
/// </summary>
public int SortOrder
{
get;
private set;
}
/// <summary>
/// Gets or sets any additional settings required by the processor.
/// </summary>
@ -72,42 +43,6 @@ namespace ImageProcessor.Processors
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 = int.Parse(match.Value.Split('=')[1], CultureInfo.InvariantCulture);
this.DynamicParameter = percentage;
}
index += 1;
}
}
return this.SortOrder;
}
/// <summary>
/// Processes the image.
/// </summary>
@ -142,19 +77,19 @@ namespace ImageProcessor.Processors
ColorMatrix colorMatrix =
new ColorMatrix(
new float[][]
new[]
{
new float[]
new[]
{
saturationComplementR + saturationFactor, saturationComplementR,
saturationComplementR, 0, 0
},
new float[]
new[]
{
saturationComplementG, saturationComplementG + saturationFactor,
saturationComplementG, 0, 0
},
new float[]
new[]
{
saturationComplementB, saturationComplementB,
saturationComplementB + saturationFactor, 0, 0
@ -196,4 +131,4 @@ namespace ImageProcessor.Processors
}
#endregion
}
}
}

6
src/TestWebsites/NET45/Test_Website_NET45/Web.config

@ -7,9 +7,9 @@
<configuration>
<configSections>
<sectionGroup name="imageProcessor">
<section name="security" requirePermission="false" type="ImageProcessor.Web.Config.ImageSecuritySection, ImageProcessor.Web"/>
<section name="processing" requirePermission="false" type="ImageProcessor.Web.Config.ImageProcessingSection, ImageProcessor.Web"/>
<section name="cache" requirePermission="false" type="ImageProcessor.Web.Config.ImageCacheSection, ImageProcessor.Web"/>
<section name="security" requirePermission="false" type="ImageProcessor.Web.Configuration.ImageSecuritySection, ImageProcessor.Web"/>
<section name="processing" requirePermission="false" type="ImageProcessor.Web.Configuration.ImageProcessingSection, ImageProcessor.Web"/>
<section name="cache" requirePermission="false" type="ImageProcessor.Web.Configuration.ImageCacheSection, ImageProcessor.Web"/>
</sectionGroup>
</configSections>
<imageProcessor >

44
src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config

@ -1,44 +1,40 @@
<?xml version="1.0" encoding="utf-8" ?>
<processing preserveExifMetaData="false">
<processing preserveExifMetaData="false">
<presets>
<preset name="demo" value="width=300&#038;height=150&#038;bgcolor=transparent"/>
</presets>
<plugins autoLoadPlugins="true">
<plugin name="Alpha" type="ImageProcessor.Processors.Alpha, ImageProcessor"/>
<plugin name="Brightness" type="ImageProcessor.Processors.Brightness, ImageProcessor"/>
<plugin name="Contrast" type="ImageProcessor.Processors.Contrast, ImageProcessor"/>
<plugin name="Crop" type="ImageProcessor.Processors.Crop, ImageProcessor"/>
<plugin name="Filter" type="ImageProcessor.Processors.Filter, ImageProcessor"/>
<plugin name="Flip" type="ImageProcessor.Processors.Flip, ImageProcessor"/>
<plugin name="Format" type="ImageProcessor.Processors.Format, ImageProcessor"/>
<plugin name="GaussianBlur" type="ImageProcessor.Processors.GaussianBlur, ImageProcessor">
<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.Processors.GaussianSharpen, ImageProcessor">
<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.Processors.Quality, ImageProcessor"/>
<plugin name="Resize" type="ImageProcessor.Processors.Resize, ImageProcessor">
<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="3000"/>
<setting key="MaxHeight" value="3000"/>
<!--<setting key="RestrictTo" value="width=300"/>-->
<setting key="MaxWidth" value="5000"/>
<setting key="MaxHeight" value="5000"/>
</settings>
</plugin>
<plugin name="Rotate" type="ImageProcessor.Processors.Rotate, ImageProcessor"/>
<plugin name="RoundedCorners" type="ImageProcessor.Processors.RoundedCorners, ImageProcessor"/>
<plugin name="Saturation" type="ImageProcessor.Processors.Saturation, ImageProcessor"/>
<plugin name="Tint" type="ImageProcessor.Processors.Tint, ImageProcessor"/>
<plugin name="Vignette" type="ImageProcessor.Processors.Vignette, ImageProcessor"/>
<plugin name="Watermark" type="ImageProcessor.Processors.Watermark, ImageProcessor"/>
<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>

Loading…
Cancel
Save