From e5f8a6cc5362df9eab8058a72a50cf227ed1b44e Mon Sep 17 00:00:00 2001 From: James South Date: Mon, 24 Feb 2014 14:20:34 +0000 Subject: [PATCH] Fixes #31 Former-commit-id: d4b957a310994456b811ae46a6fefb06d8bcff27 --- src/ImageProcessor/Processors/Resize.cs | 38 ++++++++++++++----- .../config/imageprocessor/processing.config | 4 +- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/ImageProcessor/Processors/Resize.cs b/src/ImageProcessor/Processors/Resize.cs index 577c9bb2e..94b0bcef4 100644 --- a/src/ImageProcessor/Processors/Resize.cs +++ b/src/ImageProcessor/Processors/Resize.cs @@ -152,7 +152,7 @@ namespace ImageProcessor.Processors Upscale = !UpscaleRegex.IsMatch(toParse), }; - resizeLayer.CenterCoordinates= this.ParseCoordinates(toParse); + resizeLayer.CenterCoordinates = this.ParseCoordinates(toParse); this.DynamicParameter = resizeLayer; return this.SortOrder; @@ -225,8 +225,8 @@ namespace ImageProcessor.Processors /// /// Whether to allow up-scaling of images. (Default true) /// - /// - /// 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 /// /// /// The processed image from the current instance of the class. @@ -257,7 +257,7 @@ namespace ImageProcessor.Processors int maxWidth = defaultMaxWidth > 0 ? defaultMaxWidth : int.MaxValue; int maxHeight = defaultMaxHeight > 0 ? defaultMaxHeight : int.MaxValue; - + // Fractional variants for preserving aspect ratio. double percentHeight = Math.Abs(height / (double)sourceHeight); double percentWidth = Math.Abs(width / (double)sourceWidth); @@ -295,16 +295,20 @@ namespace ImageProcessor.Processors { 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); if (destinationY > 0) + { destinationY = 0; + } if (destinationY < (int)(height - (sourceHeight * ratio))) + { destinationY = (int)(height - (sourceHeight * ratio)); + } } else { @@ -328,16 +332,20 @@ namespace ImageProcessor.Processors { 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); if (destinationX > 0) + { destinationX = 0; + } if (destinationX < (int)(width - (sourceWidth * ratio))) + { destinationX = (int)(width - (sourceWidth * ratio)); + } } else { @@ -397,7 +405,14 @@ namespace ImageProcessor.Processors bool reject = true; 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; } @@ -644,6 +659,11 @@ namespace ImageProcessor.Processors return sizes; } + /// + /// Parses the coordinates. + /// + /// The input. + /// The array containing the coordinates private float[] ParseCoordinates(string input) { float[] floats = { }; diff --git a/src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config b/src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config index 654a9fbd6..98d50805f 100644 --- a/src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config +++ b/src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config @@ -1,7 +1,7 @@  - + @@ -30,7 +30,7 @@ - +