Browse Source

Final tweaks before release.

Former-commit-id: 2b8cd49a64c4c5b7a5fc629880d015945c8135de
Former-commit-id: 9520ea81ebea34f278d29d24a8c20f3d34d75e75
Former-commit-id: 361a052d134f98676360846e719f0c5ad5066f40
af/merge-core
James South 11 years ago
parent
commit
c6e1c26536
  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> <tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff Cair Seam Carving</tags>
<dependencies> <dependencies>
<group targetFramework=".NETFramework4.5"> <group targetFramework=".NETFramework4.5">
<dependency id="ImageProcessor" version="2.0.0.0" /> <dependency id="ImageProcessor" version="2.2.3.0" />
</group> </group>
</dependencies> </dependencies>
</metadata> </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> <tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff WebP</tags>
<dependencies> <dependencies>
<group targetFramework=".NETFramework4.5"> <group targetFramework=".NETFramework4.5">
<dependency id="ImageProcessor" version="2.0.0.0" /> <dependency id="ImageProcessor" version="2.2.3.0" />
</group> </group>
</dependencies> </dependencies>
</metadata> </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> <tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff ASP Cache EXIF</tags>
<dependencies> <dependencies>
<group targetFramework=".NETFramework4.5"> <group targetFramework=".NETFramework4.5">
<dependency id="ImageProcessor" version="2.2.0.0" /> <dependency id="ImageProcessor" version="2.2.3.0" />
<dependency id="ImageProcessor.Web" version="4.2.0.0" /> <dependency id="ImageProcessor.Web" version="4.3.0.0" />
</group> </group>
</dependencies> </dependencies>
</metadata> </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> <tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff Azure Cache Asp</tags>
<dependencies> <dependencies>
<group targetFramework=".NETFramework4.5"> <group targetFramework=".NETFramework4.5">
<dependency id="ImageProcessor" version="2.2.0.0" /> <dependency id="ImageProcessor" version="2.2.3.0" />
<dependency id="ImageProcessor.Web" version="4.2.0.0" /> <dependency id="ImageProcessor.Web" version="4.3.0.0" />
<dependency id="ImageProcessor.Web.Config" version="2.2.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.Edm" version="5.6.2" />
<dependency id="Microsoft.Data.OData" version="5.6.2" /> <dependency id="Microsoft.Data.OData" version="5.6.2" />
<dependency id="Microsoft.Data.Services.Client" 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> <tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff ASP Cache EXIF</tags>
<dependencies> <dependencies>
<group targetFramework=".NETFramework4.5"> <group targetFramework=".NETFramework4.5">
<dependency id="ImageProcessor" version="2.2.0.0" /> <dependency id="ImageProcessor" version="2.2.3.0" />
<dependency id="ImageProcessor.Web" version="4.2.0.0" /> <dependency id="ImageProcessor.Web" version="4.3.0.0" />
</group> </group>
</dependencies> </dependencies>
</metadata> </metadata>

4
build/NuSpecs/ImageProcessor.Web.nuspec

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

22
build/build.xml

@ -13,7 +13,7 @@
<project> <project>
<name>ImageProcessor Web</name> <name>ImageProcessor Web</name>
<version>4.2.1.0</version> <version>4.3.0.0</version>
<folder>..\src\ImageProcessor.Web</folder> <folder>..\src\ImageProcessor.Web</folder>
<projfile>ImageProcessor.Web.csproj</projfile> <projfile>ImageProcessor.Web.csproj</projfile>
<outputs> <outputs>
@ -22,9 +22,15 @@
<nuspec>ImageProcessor.Web.nuspec</nuspec> <nuspec>ImageProcessor.Web.nuspec</nuspec>
</project> </project>
<project>
<name>ImageProcessor Web.config sample</name>
<version>2.2.1.0</version>
<nuspec>ImageProcessor.Web.Config.nuspec</nuspec>
</project>
<project> <project>
<name>ImageProcessor Web PostProcessor</name> <name>ImageProcessor Web PostProcessor</name>
<version>1.0.2.0</version> <version>1.0.3.0</version>
<folder>..\src\ImageProcessor.Web.PostProcessor</folder> <folder>..\src\ImageProcessor.Web.PostProcessor</folder>
<projfile>ImageProcessor.Web.PostProcessor.csproj</projfile> <projfile>ImageProcessor.Web.PostProcessor.csproj</projfile>
<outputs> <outputs>
@ -33,15 +39,9 @@
<nuspec>ImageProcessor.Web.PostProcessor.nuspec</nuspec> <nuspec>ImageProcessor.Web.PostProcessor.nuspec</nuspec>
</project> </project>
<project>
<name>ImageProcessor Web.config sample</name>
<version>2.2.0.0</version>
<nuspec>ImageProcessor.Web.Config.nuspec</nuspec>
</project>
<project> <project>
<name>ImageProcessor Web Azure Blob Cache plugin</name> <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> <folder>..\src\Plugins\ImageProcessor.Web\ImageProcessor.Web.Plugins.AzureBlobCache</folder>
<projfile>ImageProcessor.Web.Plugins.AzureBlobCache.csproj</projfile> <projfile>ImageProcessor.Web.Plugins.AzureBlobCache.csproj</projfile>
<outputs> <outputs>
@ -52,7 +52,7 @@
<project> <project>
<name>ImageProcessor Cair plugin</name> <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> <folder>..\src\Plugins\ImageProcessor\ImageProcessor.Plugins.Cair</folder>
<projfile>ImageProcessor.Plugins.Cair.csproj</projfile> <projfile>ImageProcessor.Plugins.Cair.csproj</projfile>
<outputs> <outputs>
@ -63,7 +63,7 @@
<project> <project>
<name>ImageProcessor WebP plugin</name> <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> <folder>..\src\Plugins\ImageProcessor\ImageProcessor.Plugins.WebP</folder>
<projfile>ImageProcessor.Plugins.WebP.csproj</projfile> <projfile>ImageProcessor.Plugins.WebP.csproj</projfile>
<outputs> <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.Collections.Specialized;
using System.Drawing; using System.Drawing;
using System.Web; using System.Web;
@ -10,7 +21,7 @@
using NUnit.Framework; using NUnit.Framework;
/// <summary> /// <summary>
/// The query param parser unit tests. /// The query parameter parser unit tests.
/// </summary> /// </summary>
[TestFixture] [TestFixture]
public class QueryParamParserUnitTests public class QueryParamParserUnitTests
@ -44,6 +55,18 @@
Assert.IsNotNull(result); 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")]
[TestCase("entropycrop=0", "entropycrop")] [TestCase("entropycrop=0", "entropycrop")]
[TestCase("entropycrop=128", "entropycrop")] [TestCase("entropycrop=128", "entropycrop")]

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

@ -106,14 +106,24 @@ namespace ImageProcessor.Web.UnitTests
[Test] [Test]
public void TestCropRegex() public void TestCropRegex()
{ {
const string Querystring = "crop=0,0,150,300"; Dictionary<string, CropLayer> data = new Dictionary<string, CropLayer>
CropLayer expected = new CropLayer(0, 0, 150, 300, CropMode.Pixels); {
{
"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(); Processors.Crop crop = new Processors.Crop();
crop.MatchRegexIndex(Querystring);
CropLayer actual = crop.Processor.DynamicParameter; foreach (KeyValuePair<string, CropLayer> item in data)
Assert.AreEqual(expected, actual); {
crop.MatchRegexIndex(item.Key);
CropLayer result = crop.Processor.DynamicParameter;
Assert.AreEqual(item.Value, result);
}
} }
/// <summary> /// <summary>
@ -252,12 +262,18 @@ namespace ImageProcessor.Web.UnitTests
{ {
"height=300", new ResizeLayer(new Size(0, 300)) "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) "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&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)) "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=-270", -270F)] [TestCase("rotate=-270", -270F)]
[TestCase("rotate=28", 28F)] [TestCase("rotate=28", 28F)]
[TestCase("rotate=28.7", 28.7F)]
public void TestRotateRegex(string input, float expected) public void TestRotateRegex(string input, float expected)
{ {
Processors.Rotate rotate = new Processors.Rotate(); Processors.Rotate rotate = new Processors.Rotate();
@ -439,6 +456,22 @@ namespace ImageProcessor.Web.UnitTests
DropShadow = true, DropShadow = true,
FontFamily = new FontFamily("arial") 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"]; string origin = context.Request.Headers["Origin"];
if (this.IsValidOriginRequest(origin)) if (this.IsValidCorsRequest(origin))
{ {
response.AddHeader("Access-Control-Allow-Origin", origin); response.AddHeader("Access-Control-Allow-Origin", origin);
} }
@ -626,7 +626,7 @@ namespace ImageProcessor.Web.HttpModules
/// <returns> /// <returns>
/// <c>True</c> if the request is valid; otherwise, <c>False</c>. /// <c>True</c> if the request is valid; otherwise, <c>False</c>.
/// </returns> /// </returns>
private bool IsValidOriginRequest(string path) private bool IsValidCorsRequest(string path)
{ {
ImageSecuritySection.CORSOriginElement origins = ImageSecuritySection.CORSOriginElement origins =
ImageProcessorConfiguration.Instance.GetImageSecuritySection().CORSOrigin; ImageProcessorConfiguration.Instance.GetImageSecuritySection().CORSOrigin;

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

@ -124,23 +124,27 @@ namespace ImageProcessor.Web.Processors
string heightRatio = queryCollection["heightratio"]; string heightRatio = queryCollection["heightratio"];
Size size = new Size(); 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. // First cater for single dimensions.
if (width != null && height == null) 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) 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 // Both supplied
if (width != null && height != null) if (width != null && height != null)
{ {
size = new Size( size = new Size(
QueryParamParser.Instance.ParseValue<int>(width), (int)Math.Round(QueryParamParser.Instance.ParseValue<float>(width), Rounding),
QueryParamParser.Instance.ParseValue<int>(height)); (int)Math.Round(QueryParamParser.Instance.ParseValue<float>(height), Rounding));
} }
// Calculate any ratio driven sizes. // Calculate any ratio driven sizes.
@ -149,13 +153,13 @@ namespace ImageProcessor.Web.Processors
// Replace 0 width // Replace 0 width
if (size.Width == 0 && size.Height > 0 && widthRatio != null && heightRatio == null) 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 // Replace 0 height
if (size.Width > 0 && size.Height == 0 && widthRatio == null && heightRatio != null) 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), FontSize = this.ParseFontSize(queryCollection),
FontFamily = this.ParseFontFamily(queryCollection), FontFamily = this.ParseFontFamily(queryCollection),
Style = this.ParseFontStyle(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); textLayer.Opacity = this.ParseOpacity(queryCollection, textLayer.FontColor);
@ -198,7 +200,7 @@ namespace ImageProcessor.Web.Processors
/// The <see cref="NameValueCollection"/> of query parameters. /// The <see cref="NameValueCollection"/> of query parameters.
/// </param> /// </param>
/// <returns> /// <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> /// </returns>
private bool ParseDropShadow(NameValueCollection queryCollection) private bool ParseDropShadow(NameValueCollection queryCollection)
{ {
@ -229,6 +231,33 @@ namespace ImageProcessor.Web.Processors
: 100; : 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 #endregion
} }
} }

Loading…
Cancel
Save