Browse Source

Final tweaks before release.

Former-commit-id: 38082dbda2033c12d2663e60fdf3e7d573590cc9
Former-commit-id: a3011bb3974337d23d4ed916f2d2b65452ecbfd4
Former-commit-id: 60efdae1250100e6d85685f0471668a51ba0e68b
af/merge-core
James South 11 years ago
parent
commit
3f7341a889
  1. 2
      build/NuSpecs/ImageProcessor.Plugins.Cair.nuspec
  2. 2
      build/NuSpecs/ImageProcessor.Plugins.WebP.nuspec
  3. 4
      build/NuSpecs/ImageProcessor.Web.Config.nuspec
  4. 6
      build/NuSpecs/ImageProcessor.Web.Plugins.AzureBlobCache.nuspec
  5. 4
      build/NuSpecs/ImageProcessor.Web.PostProcessor.nuspec
  6. 4
      build/NuSpecs/ImageProcessor.Web.nuspec
  7. 22
      build/build.xml
  8. 27
      src/ImageProcessor.Web.UnitTests/QueryParamParserUnitTests.cs
  9. 43
      src/ImageProcessor.Web.UnitTests/RegularExpressionUnitTests.cs
  10. 4
      src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs
  11. 16
      src/ImageProcessor.Web/Processors/Resize.cs
  12. 33
      src/ImageProcessor.Web/Processors/Watermark.cs

2
build/NuSpecs/ImageProcessor.Plugins.Cair.nuspec

@ -21,7 +21,7 @@ Feedback is always welcome</description>
<tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff Cair Seam Carving</tags>
<dependencies>
<group targetFramework=".NETFramework4.5">
<dependency id="ImageProcessor" version="2.0.0.0" />
<dependency id="ImageProcessor" version="2.2.3.0" />
</group>
</dependencies>
</metadata>

2
build/NuSpecs/ImageProcessor.Plugins.WebP.nuspec

@ -21,7 +21,7 @@ Feedback is always welcome</description>
<tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff WebP</tags>
<dependencies>
<group targetFramework=".NETFramework4.5">
<dependency id="ImageProcessor" version="2.0.0.0" />
<dependency id="ImageProcessor" version="2.2.3.0" />
</group>
</dependencies>
</metadata>

4
build/NuSpecs/ImageProcessor.Web.Config.nuspec

@ -21,8 +21,8 @@ Feedback is always welcome</description>
<tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff ASP Cache EXIF</tags>
<dependencies>
<group targetFramework=".NETFramework4.5">
<dependency id="ImageProcessor" version="2.2.0.0" />
<dependency id="ImageProcessor.Web" version="4.2.0.0" />
<dependency id="ImageProcessor" version="2.2.3.0" />
<dependency id="ImageProcessor.Web" version="4.3.0.0" />
</group>
</dependencies>
</metadata>

6
build/NuSpecs/ImageProcessor.Web.Plugins.AzureBlobCache.nuspec

@ -21,9 +21,9 @@ Feedback is always welcome</description>
<tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff Azure Cache Asp</tags>
<dependencies>
<group targetFramework=".NETFramework4.5">
<dependency id="ImageProcessor" version="2.2.0.0" />
<dependency id="ImageProcessor.Web" version="4.2.0.0" />
<dependency id="ImageProcessor.Web.Config" version="2.2.0.0" />
<dependency id="ImageProcessor" version="2.2.3.0" />
<dependency id="ImageProcessor.Web" version="4.3.0.0" />
<dependency id="ImageProcessor.Web.Config" version="2.2.1.0" />
<dependency id="Microsoft.Data.Edm" version="5.6.2" />
<dependency id="Microsoft.Data.OData" version="5.6.2" />
<dependency id="Microsoft.Data.Services.Client" version="5.6.2" />

4
build/NuSpecs/ImageProcessor.Web.PostProcessor.nuspec

@ -21,8 +21,8 @@ Feedback is always welcome</description>
<tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff ASP Cache EXIF</tags>
<dependencies>
<group targetFramework=".NETFramework4.5">
<dependency id="ImageProcessor" version="2.2.0.0" />
<dependency id="ImageProcessor.Web" version="4.2.0.0" />
<dependency id="ImageProcessor" version="2.2.3.0" />
<dependency id="ImageProcessor.Web" version="4.3.0.0" />
</group>
</dependencies>
</metadata>

4
build/NuSpecs/ImageProcessor.Web.nuspec

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>ImageProcessor.Web</id>
<version>4.2.1.0</version>
<version>4.3.0.0</version>
<title>ImageProcessor.Web</title>
<authors>James South</authors>
<owners>James South</owners>
@ -23,7 +23,7 @@ Feedback is always welcome</description>
<tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff ASP Cache EXIF</tags>
<dependencies>
<group targetFramework=".NETFramework4.5">
<dependency id="ImageProcessor" version="2.2.0.0" />
<dependency id="ImageProcessor" version="2.2.3.0" />
</group>
</dependencies>
</metadata>

22
build/build.xml

@ -13,7 +13,7 @@
<project>
<name>ImageProcessor Web</name>
<version>4.2.1.0</version>
<version>4.3.0.0</version>
<folder>..\src\ImageProcessor.Web</folder>
<projfile>ImageProcessor.Web.csproj</projfile>
<outputs>
@ -22,9 +22,15 @@
<nuspec>ImageProcessor.Web.nuspec</nuspec>
</project>
<project>
<name>ImageProcessor Web.config sample</name>
<version>2.2.1.0</version>
<nuspec>ImageProcessor.Web.Config.nuspec</nuspec>
</project>
<project>
<name>ImageProcessor Web PostProcessor</name>
<version>1.0.2.0</version>
<version>1.0.3.0</version>
<folder>..\src\ImageProcessor.Web.PostProcessor</folder>
<projfile>ImageProcessor.Web.PostProcessor.csproj</projfile>
<outputs>
@ -33,15 +39,9 @@
<nuspec>ImageProcessor.Web.PostProcessor.nuspec</nuspec>
</project>
<project>
<name>ImageProcessor Web.config sample</name>
<version>2.2.0.0</version>
<nuspec>ImageProcessor.Web.Config.nuspec</nuspec>
</project>
<project>
<name>ImageProcessor Web Azure Blob Cache plugin</name>
<version>1.0.0.0</version>
<version>1.0.1.0</version>
<folder>..\src\Plugins\ImageProcessor.Web\ImageProcessor.Web.Plugins.AzureBlobCache</folder>
<projfile>ImageProcessor.Web.Plugins.AzureBlobCache.csproj</projfile>
<outputs>
@ -52,7 +52,7 @@
<project>
<name>ImageProcessor Cair plugin</name>
<version>1.0.0.0</version>
<version>1.0.1.0</version>
<folder>..\src\Plugins\ImageProcessor\ImageProcessor.Plugins.Cair</folder>
<projfile>ImageProcessor.Plugins.Cair.csproj</projfile>
<outputs>
@ -63,7 +63,7 @@
<project>
<name>ImageProcessor WebP plugin</name>
<version>1.0.1.0</version>
<version>1.0.2.0</version>
<folder>..\src\Plugins\ImageProcessor\ImageProcessor.Plugins.WebP</folder>
<projfile>ImageProcessor.Plugins.WebP.csproj</projfile>
<outputs>

27
src/ImageProcessor.Web.UnitTests/QueryParamParserUnitTests.cs

@ -1,5 +1,16 @@
namespace ImageProcessor.Web.UnitTests
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="QueryParamParserUnitTests.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// <summary>
// The query parameter parser unit tests.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Web.UnitTests
{
using System;
using System.Collections.Specialized;
using System.Drawing;
using System.Web;
@ -10,7 +21,7 @@
using NUnit.Framework;
/// <summary>
/// The query param parser unit tests.
/// The query parameter parser unit tests.
/// </summary>
[TestFixture]
public class QueryParamParserUnitTests
@ -44,6 +55,18 @@
Assert.IsNotNull(result);
}
[TestCase("", "entropycrop", 0)]
[TestCase("entropycrop=0", "entropycrop", 0)]
[TestCase("entropycrop=128", "entropycrop", 128)]
[TestCase("entropycrop=128.4", "entropycrop", 128)]
[TestCase("entropycrop=128.5", "entropycrop", 129)]
public void IntRounded(string queryString, string parameter, int expected)
{
NameValueCollection query = HttpUtility.ParseQueryString(queryString);
int result = (int)Math.Round(QueryParamParser.Instance.ParseValue<float>(query[parameter]), MidpointRounding.AwayFromZero);
Assert.AreEqual(result, expected);
}
[TestCase("", "entropycrop")]
[TestCase("entropycrop=0", "entropycrop")]
[TestCase("entropycrop=128", "entropycrop")]

43
src/ImageProcessor.Web.UnitTests/RegularExpressionUnitTests.cs

@ -106,14 +106,24 @@ namespace ImageProcessor.Web.UnitTests
[Test]
public void TestCropRegex()
{
const string Querystring = "crop=0,0,150,300";
CropLayer expected = new CropLayer(0, 0, 150, 300, CropMode.Pixels);
Dictionary<string, CropLayer> data = new Dictionary<string, CropLayer>
{
{
"crop=0,0,150,300", new CropLayer(0, 0, 150, 300, CropMode.Pixels)
},
{
"crop=0.1,0.1,.2,.2&cropmode=percentage", new CropLayer(0.1f, 0.1f, 0.2f, 0.2f, CropMode.Percentage)
}
};
Processors.Crop crop = new Processors.Crop();
crop.MatchRegexIndex(Querystring);
CropLayer actual = crop.Processor.DynamicParameter;
Assert.AreEqual(expected, actual);
foreach (KeyValuePair<string, CropLayer> item in data)
{
crop.MatchRegexIndex(item.Key);
CropLayer result = crop.Processor.DynamicParameter;
Assert.AreEqual(item.Value, result);
}
}
/// <summary>
@ -252,12 +262,18 @@ namespace ImageProcessor.Web.UnitTests
{
"height=300", new ResizeLayer(new Size(0, 300))
},
{
"height=300.6", new ResizeLayer(new Size(0, 301))
},
{
"height=300&mode=crop", new ResizeLayer(new Size(0, 300), ResizeMode.Crop)
},
{
"width=300&mode=crop", new ResizeLayer(new Size(300, 0), ResizeMode.Crop)
},
{
"width=300.2&mode=crop", new ResizeLayer(new Size(300, 0), ResizeMode.Crop)
},
{
"width=600&heightratio=0.416", new ResizeLayer(new Size(600, 250))
},
@ -289,6 +305,7 @@ namespace ImageProcessor.Web.UnitTests
[TestCase("rotate=270", 270F)]
[TestCase("rotate=-270", -270F)]
[TestCase("rotate=28", 28F)]
[TestCase("rotate=28.7", 28.7F)]
public void TestRotateRegex(string input, float expected)
{
Processors.Rotate rotate = new Processors.Rotate();
@ -439,6 +456,22 @@ namespace ImageProcessor.Web.UnitTests
DropShadow = true,
FontFamily = new FontFamily("arial")
}
},
{
"watermark=لا أحد يحب الألم بذاته، يسعى ورائه أو يبتغيه، ببساطة لأنه الألم&color=fff&fontsize=36&fontstyle=italic&fontopacity=80&textposition=30,150&dropshadow=true&fontfamily=arial&vertical=true&rtl=true",
new TextLayer
{
Text = "لا أحد يحب الألم بذاته، يسعى ورائه أو يبتغيه، ببساطة لأنه الألم",
FontColor = ColorTranslator.FromHtml("#" + "ffffff"),
FontSize = 36,
Style = FontStyle.Italic,
Opacity = 80,
Position = new Point(30, 150),
DropShadow = true,
FontFamily = new FontFamily("arial"),
Vertical = true,
RightToLeft = true
}
}
};

4
src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs

@ -522,7 +522,7 @@ namespace ImageProcessor.Web.HttpModules
{
string origin = context.Request.Headers["Origin"];
if (this.IsValidOriginRequest(origin))
if (this.IsValidCorsRequest(origin))
{
response.AddHeader("Access-Control-Allow-Origin", origin);
}
@ -626,7 +626,7 @@ namespace ImageProcessor.Web.HttpModules
/// <returns>
/// <c>True</c> if the request is valid; otherwise, <c>False</c>.
/// </returns>
private bool IsValidOriginRequest(string path)
private bool IsValidCorsRequest(string path)
{
ImageSecuritySection.CORSOriginElement origins =
ImageProcessorConfiguration.Instance.GetImageSecuritySection().CORSOrigin;

16
src/ImageProcessor.Web/Processors/Resize.cs

@ -124,23 +124,27 @@ namespace ImageProcessor.Web.Processors
string heightRatio = queryCollection["heightratio"];
Size size = new Size();
// Umbraco calls the API incorrectly so we have to deal with floats.
// We round up so that single pixel lines are not produced.
const MidpointRounding Rounding = MidpointRounding.AwayFromZero;
// First cater for single dimensions.
if (width != null && height == null)
{
size = new Size(QueryParamParser.Instance.ParseValue<int>(width), 0);
size = new Size((int)Math.Round(QueryParamParser.Instance.ParseValue<float>(width), Rounding), 0);
}
if (width == null && height != null)
{
size = new Size(0, QueryParamParser.Instance.ParseValue<int>(height));
size = new Size(0, (int)Math.Round(QueryParamParser.Instance.ParseValue<float>(height), Rounding));
}
// Both supplied
if (width != null && height != null)
{
size = new Size(
QueryParamParser.Instance.ParseValue<int>(width),
QueryParamParser.Instance.ParseValue<int>(height));
(int)Math.Round(QueryParamParser.Instance.ParseValue<float>(width), Rounding),
(int)Math.Round(QueryParamParser.Instance.ParseValue<float>(height), Rounding));
}
// Calculate any ratio driven sizes.
@ -149,13 +153,13 @@ namespace ImageProcessor.Web.Processors
// Replace 0 width
if (size.Width == 0 && size.Height > 0 && widthRatio != null && heightRatio == null)
{
size.Width = Convert.ToInt32(QueryParamParser.Instance.ParseValue<float>(widthRatio) * size.Height);
size.Width = (int)Math.Round(QueryParamParser.Instance.ParseValue<float>(widthRatio) * size.Height, Rounding);
}
// Replace 0 height
if (size.Width > 0 && size.Height == 0 && widthRatio == null && heightRatio != null)
{
size.Height = Convert.ToInt32(QueryParamParser.Instance.ParseValue<float>(heightRatio) * size.Width);
size.Height = (int)Math.Round(QueryParamParser.Instance.ParseValue<float>(heightRatio) * size.Width, Rounding);
}
}

33
src/ImageProcessor.Web/Processors/Watermark.cs

@ -85,7 +85,9 @@ namespace ImageProcessor.Web.Processors
FontSize = this.ParseFontSize(queryCollection),
FontFamily = this.ParseFontFamily(queryCollection),
Style = this.ParseFontStyle(queryCollection),
DropShadow = this.ParseDropShadow(queryCollection)
DropShadow = this.ParseDropShadow(queryCollection),
Vertical = this.ParseVertical(queryCollection),
RightToLeft = this.ParseRightToLeft(queryCollection)
};
textLayer.Opacity = this.ParseOpacity(queryCollection, textLayer.FontColor);
@ -198,7 +200,7 @@ namespace ImageProcessor.Web.Processors
/// The <see cref="NameValueCollection"/> of query parameters.
/// </param>
/// <returns>
/// The true if the watermark is to have a shadow; otherwise false.
/// True if the watermark is to have a shadow; otherwise false.
/// </returns>
private bool ParseDropShadow(NameValueCollection queryCollection)
{
@ -229,6 +231,33 @@ namespace ImageProcessor.Web.Processors
: 100;
}
/// <summary>
/// Returns a value indicating whether the watermark is to be written right to left.
/// </summary>
/// <param name="queryCollection">
/// The <see cref="NameValueCollection"/> of query parameters.
/// </param>
/// <returns>
/// True if the watermark is to be written right to left; otherwise false.
/// </returns>
private bool ParseRightToLeft(NameValueCollection queryCollection)
{
return QueryParamParser.Instance.ParseValue<bool>(queryCollection["rtl"]);
}
/// <summary>
/// Returns a value indicating whether the watermark is to be written vertically.
/// </summary>
/// <param name="queryCollection">
/// The <see cref="NameValueCollection"/> of query parameters.
/// </param>
/// <returns>
/// True if the watermark is to be written vertically; otherwise false.
/// </returns>
private bool ParseVertical(NameValueCollection queryCollection)
{
return QueryParamParser.Instance.ParseValue<bool>(queryCollection["vertical"]);
}
#endregion
}
}

Loading…
Cancel
Save