From df5c95cdb81d1ed50bae15fc17b006825e600727 Mon Sep 17 00:00:00 2001 From: perploug Date: Thu, 20 Feb 2014 08:35:47 +0100 Subject: [PATCH] Tweaking the center calculation abit Former-commit-id: 1c29005edce7d8ddf809c1a11cc491beaf90e7eb --- src/ImageProcessor/Processors/Resize.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/ImageProcessor/Processors/Resize.cs b/src/ImageProcessor/Processors/Resize.cs index e4d6e7eae6..577c9bb2e3 100644 --- a/src/ImageProcessor/Processors/Resize.cs +++ b/src/ImageProcessor/Processors/Resize.cs @@ -297,11 +297,13 @@ namespace ImageProcessor.Processors if (centerCoordinates.Any()) { - destinationY = (int)((centerCoordinates[0] * sourceHeight) * ratio) - (height / 2); - if (destinationY < 0) + var center = -(ratio * sourceHeight) * centerCoordinates[0]; + destinationY = (int)center + (height / 2); + + if (destinationY > 0) destinationY = 0; - if (destinationY + height > (sourceHeight * ratio)) + if (destinationY < (int)(height - (sourceHeight * ratio))) destinationY = (int)(height - (sourceHeight * ratio)); } else @@ -328,11 +330,13 @@ namespace ImageProcessor.Processors if (centerCoordinates.Any()) { - destinationX = (int)((centerCoordinates[1] * sourceWidth) * ratio) - (width / 2); - if (destinationX < 0) + var center = -(ratio * sourceWidth) * centerCoordinates[1]; + destinationX = (int)center + (width / 2); + + if (destinationX > 0) destinationX = 0; - if (destinationX + width > (sourceWidth * ratio)) + if (destinationX < (int)(width - (sourceWidth * ratio))) destinationX = (int)(width - (sourceWidth * ratio)); } else