From 9fb7b0ab64d714e4603c0cea8ad69807e366cee0 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: f5721fe3086cb7715d2f89d60a2b078fe133050a Former-commit-id: 713ca5bfb22acbc23ebd432cd97903af368195ee --- 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 eaaedbb16f..7fd24c6743 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 4fed9c4b56..6a1121433b 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