Browse Source

Fixes #31

Former-commit-id: d2470b5e658916b6e3850604e6049275fe1d2696
af/merge-core
James South 12 years ago
parent
commit
8263907f86
  1. 38
      src/ImageProcessor/Processors/Resize.cs
  2. 4
      src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config

38
src/ImageProcessor/Processors/Resize.cs

@ -152,7 +152,7 @@ namespace ImageProcessor.Processors
Upscale = !UpscaleRegex.IsMatch(toParse), Upscale = !UpscaleRegex.IsMatch(toParse),
}; };
resizeLayer.CenterCoordinates= this.ParseCoordinates(toParse); resizeLayer.CenterCoordinates = this.ParseCoordinates(toParse);
this.DynamicParameter = resizeLayer; this.DynamicParameter = resizeLayer;
return this.SortOrder; return this.SortOrder;
@ -225,8 +225,8 @@ namespace ImageProcessor.Processors
/// <param name="upscale"> /// <param name="upscale">
/// Whether to allow up-scaling of images. (Default true) /// Whether to allow up-scaling of images. (Default true)
/// </param> /// </param>
/// <param name="center"> /// <param name="centerCoordinates">
/// If resizemode is crop, you can set a specific center coordinate, use as alternative to anchorPosition /// If the resize mode is crop, you can set a specific center coordinate, use as alternative to anchorPosition
/// </param> /// </param>
/// <returns> /// <returns>
/// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class. /// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
@ -257,7 +257,7 @@ namespace ImageProcessor.Processors
int maxWidth = defaultMaxWidth > 0 ? defaultMaxWidth : int.MaxValue; int maxWidth = defaultMaxWidth > 0 ? defaultMaxWidth : int.MaxValue;
int maxHeight = defaultMaxHeight > 0 ? defaultMaxHeight : int.MaxValue; int maxHeight = defaultMaxHeight > 0 ? defaultMaxHeight : int.MaxValue;
// Fractional variants for preserving aspect ratio. // Fractional variants for preserving aspect ratio.
double percentHeight = Math.Abs(height / (double)sourceHeight); double percentHeight = Math.Abs(height / (double)sourceHeight);
double percentWidth = Math.Abs(width / (double)sourceWidth); double percentWidth = Math.Abs(width / (double)sourceWidth);
@ -295,16 +295,20 @@ namespace ImageProcessor.Processors
{ {
ratio = percentWidth; ratio = percentWidth;
if (centerCoordinates.Any()) if (centerCoordinates != null && centerCoordinates.Any())
{ {
var center = -(ratio * sourceHeight) * centerCoordinates[0]; double center = -(ratio * sourceHeight) * centerCoordinates[0];
destinationY = (int)center + (height / 2); destinationY = (int)center + (height / 2);
if (destinationY > 0) if (destinationY > 0)
{
destinationY = 0; destinationY = 0;
}
if (destinationY < (int)(height - (sourceHeight * ratio))) if (destinationY < (int)(height - (sourceHeight * ratio)))
{
destinationY = (int)(height - (sourceHeight * ratio)); destinationY = (int)(height - (sourceHeight * ratio));
}
} }
else else
{ {
@ -328,16 +332,20 @@ namespace ImageProcessor.Processors
{ {
ratio = percentHeight; ratio = percentHeight;
if (centerCoordinates.Any()) if (centerCoordinates != null && centerCoordinates.Any())
{ {
var center = -(ratio * sourceWidth) * centerCoordinates[1]; double center = -(ratio * sourceWidth) * centerCoordinates[1];
destinationX = (int)center + (width / 2); destinationX = (int)center + (width / 2);
if (destinationX > 0) if (destinationX > 0)
{
destinationX = 0; destinationX = 0;
}
if (destinationX < (int)(width - (sourceWidth * ratio))) if (destinationX < (int)(width - (sourceWidth * ratio)))
{
destinationX = (int)(width - (sourceWidth * ratio)); destinationX = (int)(width - (sourceWidth * ratio));
}
} }
else else
{ {
@ -397,7 +405,14 @@ namespace ImageProcessor.Processors
bool reject = true; bool reject = true;
foreach (Size restrictedSize in restrictedSizes) foreach (Size restrictedSize in restrictedSizes)
{ {
if (restrictedSize.Width == width && restrictedSize.Height == height) if (restrictedSize.Height == 0 || restrictedSize.Width == 0)
{
if (restrictedSize.Width == width || restrictedSize.Height == height)
{
reject = false;
}
}
else if (restrictedSize.Width == width && restrictedSize.Height == height)
{ {
reject = false; reject = false;
} }
@ -644,6 +659,11 @@ namespace ImageProcessor.Processors
return sizes; return sizes;
} }
/// <summary>
/// Parses the coordinates.
/// </summary>
/// <param name="input">The input.</param>
/// <returns>The <see cref="float"/> array containing the coordinates</returns>
private float[] ParseCoordinates(string input) private float[] ParseCoordinates(string input)
{ {
float[] floats = { }; float[] floats = { };

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

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<processing> <processing>
<presets> <presets>
<!--<preset name="demo" value="width=300&#038;height=150&#038;bgcolor=transparent"/>--> <preset name="demo" value="width=300&#038;height=150&#038;bgcolor=transparent"/>
</presets> </presets>
<plugins autoLoadPlugins="true"> <plugins autoLoadPlugins="true">
<plugin name="Alpha" type="ImageProcessor.Processors.Alpha, ImageProcessor"/> <plugin name="Alpha" type="ImageProcessor.Processors.Alpha, ImageProcessor"/>
@ -30,7 +30,7 @@
<settings> <settings>
<setting key="MaxWidth" value="3000"/> <setting key="MaxWidth" value="3000"/>
<setting key="MaxHeight" value="3000"/> <setting key="MaxHeight" value="3000"/>
<!--<setting key="RestrictTo" value="width=300height=300,width=300height=300"/>--> <setting key="RestrictTo" value="width=300"/>
</settings> </settings>
</plugin> </plugin>
<plugin name="Rotate" type="ImageProcessor.Processors.Rotate, ImageProcessor"/> <plugin name="Rotate" type="ImageProcessor.Processors.Rotate, ImageProcessor"/>

Loading…
Cancel
Save