From a9cfa103d3fb67c93aac9904fc68d354bfbef506 Mon Sep 17 00:00:00 2001 From: James South Date: Tue, 24 Feb 2015 22:21:23 +0000 Subject: [PATCH] Resize pad now respects anchor mode. Former-commit-id: a579d27a41aceb1421fce03a760df0dee1dbe0e3 Former-commit-id: 451175a87f191d6d1034846baf82690bf7d33030 --- src/ImageProcessor/Imaging/Resizer.cs | 28 ++++++++++++++++++-- src/TestWebsites/MVC/Views/Home/Index.cshtml | 7 ++--- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/ImageProcessor/Imaging/Resizer.cs b/src/ImageProcessor/Imaging/Resizer.cs index eaaedbb16..7fd24c674 100644 --- a/src/ImageProcessor/Imaging/Resizer.cs +++ b/src/ImageProcessor/Imaging/Resizer.cs @@ -152,14 +152,38 @@ namespace ImageProcessor.Imaging if (percentHeight < percentWidth) { ratio = percentHeight; - destinationX = Convert.ToInt32((width - (sourceWidth * ratio)) / 2); destinationWidth = Convert.ToInt32(sourceWidth * percentHeight); + + switch (anchorPosition) + { + case AnchorPosition.Left: + destinationX = 0; + break; + case AnchorPosition.Right: + destinationX = (int)(width - (sourceWidth * ratio)); + break; + default: + destinationX = Convert.ToInt32((width - (sourceWidth * ratio)) / 2); + break; + } } else { ratio = percentWidth; - destinationY = Convert.ToInt32((height - (sourceHeight * ratio)) / 2); destinationHeight = Convert.ToInt32(sourceHeight * percentWidth); + + switch (anchorPosition) + { + case AnchorPosition.Top: + destinationY = 0; + break; + case AnchorPosition.Bottom: + destinationY = (int)(height - (sourceHeight * ratio)); + break; + default: + destinationY = (int)((height - (sourceHeight * ratio)) / 2); + break; + } } } diff --git a/src/TestWebsites/MVC/Views/Home/Index.cshtml b/src/TestWebsites/MVC/Views/Home/Index.cshtml index 4fed9c4b5..6a1121433 100644 --- a/src/TestWebsites/MVC/Views/Home/Index.cshtml +++ b/src/TestWebsites/MVC/Views/Home/Index.cshtml @@ -25,18 +25,15 @@ *@ - @*
+

Reside Pad

-
- -
-
+ @*

Resize Crop