From bfd551ea89167edf80fc603d73a7d72303e92e7f 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: 01d955f39dec3aa02dda11f50c0850a72c56c636 --- 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 e4d6e7eae..577c9bb2e 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