From e8d41a1b5e25867cd7037da353b41a055d9a227d Mon Sep 17 00:00:00 2001 From: Jeavon Leopold Date: Fri, 18 Apr 2014 22:04:23 +0100 Subject: [PATCH] Adding Ratio Mode parameter to GetCropUrl helper --- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 8 ++--- .../ImageCropperTemplateExtensions.cs | 32 ++++++++++++++++--- src/Umbraco.Web/Models/ImageCropRatioMode.cs | 8 +++++ src/Umbraco.Web/Umbraco.Web.csproj | 1 + 4 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 src/Umbraco.Web/Models/ImageCropRatioMode.cs diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 903542f7dd..f0a6e7f73e 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -127,13 +127,13 @@ False ..\packages\Examine.0.1.55.2941\lib\Examine.dll - + False - ..\packages\ImageProcessor.1.8.7.0\lib\ImageProcessor.dll + ..\packages\ImageProcessor.1.8.8.0\lib\ImageProcessor.dll - + False - ..\packages\ImageProcessor.Web.3.2.1.0\lib\net45\ImageProcessor.Web.dll + ..\packages\ImageProcessor.Web.3.2.2.0\lib\net45\ImageProcessor.Web.dll False diff --git a/src/Umbraco.Web/ImageCropperTemplateExtensions.cs b/src/Umbraco.Web/ImageCropperTemplateExtensions.cs index 4d75b164f4..d9192392ff 100644 --- a/src/Umbraco.Web/ImageCropperTemplateExtensions.cs +++ b/src/Umbraco.Web/ImageCropperTemplateExtensions.cs @@ -93,6 +93,9 @@ namespace Umbraco.Web /// /// The further options. /// + /// + /// Use a dimension as a ratio + /// /// /// The . /// @@ -108,7 +111,9 @@ namespace Umbraco.Web bool preferFocalPoint = false, bool useCropDimensions = false, bool cacheBuster = true, - string furtherOptions = null) + string furtherOptions = null, + ImageCropRatioMode? ratioMode = null + ) { string imageCropperValue = null; @@ -133,7 +138,7 @@ namespace Umbraco.Web var cacheBusterValue = cacheBuster ? mediaItem.UpdateDate.ToFileTimeUtc().ToString(CultureInfo.InvariantCulture) : null; return mediaItemUrl != null - ? GetCropUrl(mediaItemUrl, width, height, imageCropperValue, cropAlias, quality, imageCropMode, imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBusterValue, furtherOptions) + ? GetCropUrl(mediaItemUrl, width, height, imageCropperValue, cropAlias, quality, imageCropMode, imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBusterValue, furtherOptions, ratioMode) : string.Empty; } @@ -176,6 +181,9 @@ namespace Umbraco.Web /// /// The further options. /// + /// + /// Use a dimension as a ratio + /// /// /// The . /// @@ -191,7 +199,9 @@ namespace Umbraco.Web bool preferFocalPoint = false, bool useCropDimensions = false, string cacheBusterValue = null, - string furtherOptions = null) + string furtherOptions = null, + ImageCropRatioMode? ratioMode = null + ) { if (string.IsNullOrEmpty(imageUrl) == false) { @@ -235,16 +245,28 @@ namespace Umbraco.Web imageResizerUrl.Append("&quality=" + quality); } - if (width != null && useCropDimensions == false) + if (width != null && useCropDimensions == false && ratioMode != ImageCropRatioMode.Width) { imageResizerUrl.Append("&width=" + width); } - if (height != null && useCropDimensions == false) + if (height != null && useCropDimensions == false && ratioMode != ImageCropRatioMode.Height) { imageResizerUrl.Append("&height=" + height); } + if (ratioMode == ImageCropRatioMode.Width) + { + var widthRatio = (decimal)width/(decimal)height; + imageResizerUrl.Append("&widthratio=" + widthRatio.ToString(CultureInfo.InvariantCulture)); + } + + if (ratioMode == ImageCropRatioMode.Height) + { + var heightRatio = (decimal)height/(decimal)width; + imageResizerUrl.Append("&heightratio=" + heightRatio.ToString(CultureInfo.InvariantCulture)); + } + if (furtherOptions != null) { imageResizerUrl.Append(furtherOptions); diff --git a/src/Umbraco.Web/Models/ImageCropRatioMode.cs b/src/Umbraco.Web/Models/ImageCropRatioMode.cs new file mode 100644 index 0000000000..9f63cdea77 --- /dev/null +++ b/src/Umbraco.Web/Models/ImageCropRatioMode.cs @@ -0,0 +1,8 @@ +namespace Umbraco.Web.Models +{ + public enum ImageCropRatioMode + { + Width, + Height + } +} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index ddf4fc326e..557b08811d 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -350,6 +350,7 @@ +