Browse Source

Adding preset ()

Former-commit-id: ce9be2ee0a0fd9b8704527142f0c71ee9e458b4c
af/merge-core
James South 13 years ago
parent
commit
aa40322e0d
  1. 6
      src/ImageProcessor.Web/NET45/ImageFactoryExtensions.cs
  2. 1
      src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj
  3. 121
      src/ImageProcessor.Web/NET45/Preset.cs
  4. 1
      src/TestWebsites/NET45/Test_Website_NET45/Views/Home/Index.cshtml
  5. 5
      src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config

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

@ -54,6 +54,12 @@ namespace ImageProcessor.Web
{
Image img = graphicsProcessor.ProcessImage(factory);
factory.Update(img);
// Break to prevent loop as Preset calls AutoProcess internally.
if (graphicsProcessor.GetType() == typeof(Preset))
{
break;
}
}
}
}

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

@ -63,6 +63,7 @@
<Compile Include="Helpers\TaskHelpers.cs" />
<Compile Include="HttpModules\ImageProcessingModule.cs" />
<Compile Include="ImageFactoryExtensions.cs" />
<Compile Include="Preset.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SQLite.cs" />
<Compile Include="SQLiteAsync.cs" />

121
src/ImageProcessor.Web/NET45/Preset.cs

@ -0,0 +1,121 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Preset.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// <summary>
// Encapsulates methods to that allow the processing of preset image processing instructions.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Web
{
using System.Collections.Generic;
using System.Drawing;
using System.Text.RegularExpressions;
using ImageProcessor.Processors;
/// <summary>
/// Encapsulates methods to that allow the processing of preset image processing instructions.
/// </summary>
public class Preset : IGraphicsProcessor
{
/// <summary>
/// The regular expression to search strings for.
/// </summary>
private static readonly Regex QueryRegex = new Regex(@"preset=[^&]*", RegexOptions.Compiled);
/// <summary>
/// Gets the regular expression to search strings for.
/// </summary>
public Regex RegexPattern
{
get
{
return QueryRegex;
}
}
/// <summary>
/// Gets DynamicParameter.
/// </summary>
public dynamic DynamicParameter
{
get;
private 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>
public Dictionary<string, string> Settings
{
get;
set;
}
/// <summary>
/// The match regex index.
/// </summary>
/// <param name="queryString">
/// The query string.
/// </param>
/// <returns>
/// The <see cref="int"/>.
/// </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;
string preset = match.Value;
this.DynamicParameter = preset;
}
index += 1;
}
}
return this.SortOrder;
}
/// <summary>
/// Processes the image.
/// </summary>
/// <param name="factory">The the current instance of the <see cref="T:ImageProcessor.ImageFactory" /> class containing
/// the image to process.</param>
/// <returns>
/// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory" /> class.
/// </returns>
public Image ProcessImage(ImageFactory factory)
{
string preset = this.DynamicParameter;
string querystring;
this.Settings.TryGetValue(preset.Split('=')[1], out querystring);
string oldQueryString = factory.QueryString;
string newQueryString = Regex.Replace(oldQueryString, preset, querystring ?? string.Empty);
return factory.AddQueryString(newQueryString).AutoProcess().Image;
}
}
}

1
src/TestWebsites/NET45/Test_Website_NET45/Views/Home/Index.cshtml

@ -10,6 +10,7 @@
<img src="/images/Penguins.jpg?width=300" />
<h3>Foreign language test.</h3>
<img src="/images/udendørs.jpg?width=300" />
<img src="/images/udendørs.jpg?preset=a&filter=comic" />
</div>
<div class="col-s-6">
<h2>Cropped </h2>

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

@ -13,6 +13,11 @@
<setting key="MaxHeight" value="3000"/>
</settings>
</plugin>
<plugin name="Preset">
<settings>
<setting key="a" value="width=300&#038;height=150"/>
</settings>
</plugin>
</plugins>
</processing>

Loading…
Cancel
Save