From cacef54ef77bdfe725aafc7af64a02048e51a2e7 Mon Sep 17 00:00:00 2001 From: Mole Date: Fri, 9 Jul 2021 09:04:07 +0200 Subject: [PATCH] Round to int instead of just converting --- .../ImageProcessors/CropWebProcessor.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web.Common/ImageProcessors/CropWebProcessor.cs b/src/Umbraco.Web.Common/ImageProcessors/CropWebProcessor.cs index 83c90d21f4..fec27a8591 100644 --- a/src/Umbraco.Web.Common/ImageProcessors/CropWebProcessor.cs +++ b/src/Umbraco.Web.Common/ImageProcessors/CropWebProcessor.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Globalization; using Microsoft.Extensions.Logging; @@ -43,11 +44,11 @@ namespace Umbraco.Cms.Web.Common.ImageProcessors private static Rectangle GetCropRectangle(int width, int height, ImageCropperCropCoordinates coordinates) { // Get coordinates of top left corner of the rectangle - var topX = decimal.ToInt32(width * coordinates.X1); - var topY = decimal.ToInt32(height * coordinates.Y1); + var topX = RoundToInt(width * coordinates.X1); + var topY = RoundToInt(height * coordinates.Y1); // Get coordinated of bottom right corner - var bottomX = decimal.ToInt32(width - (width * coordinates.X2)); - var bottomY = decimal.ToInt32(height - (height * coordinates.Y2)); + var bottomX = RoundToInt(width - (width * coordinates.X2)); + var bottomY = RoundToInt(height - (height * coordinates.Y2)); // Get width and height of crop var cropWidth = bottomX - topX; @@ -56,6 +57,8 @@ namespace Umbraco.Cms.Web.Common.ImageProcessors return new Rectangle(topX, topY, cropWidth, cropHeight); } + private static int RoundToInt(decimal number) => decimal.ToInt32(Math.Round(number)); + private static ImageCropperCropCoordinates GetCropCoordinates(IDictionary commands, CommandParser parser, CultureInfo culture) { decimal[] crops = parser.ParseValue(commands.GetValueOrDefault(Crop), culture);