From 5478f0aa484f8cca41e40516b5dc750fe73f8368 Mon Sep 17 00:00:00 2001 From: Patrice Kaufmann <41791606+patricekaufmann@users.noreply.github.com> Date: Tue, 11 Jul 2023 18:15:14 +0200 Subject: [PATCH] BUGFIX: fix specific cases where the requested croparea would be larger than the image itself --- .../src/SecondaryEditors/ImageCropper/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/neos-ui-editors/src/SecondaryEditors/ImageCropper/index.js b/packages/neos-ui-editors/src/SecondaryEditors/ImageCropper/index.js index ffab7c0302..834b01471f 100644 --- a/packages/neos-ui-editors/src/SecondaryEditors/ImageCropper/index.js +++ b/packages/neos-ui-editors/src/SecondaryEditors/ImageCropper/index.js @@ -159,8 +159,14 @@ export default class ImageCropper extends PureComponent { const normalizedAspectRatioHeight = currentAspectRatioStrategy.height / aspectRatioGcd; // pixel perfect calculations - const naturalCropWidth = Math.floor(imageWidth * (cropArea.width / 100) / normalizedAspectRatioWidth) * normalizedAspectRatioWidth; - const naturalCropHeight = naturalCropWidth / normalizedAspectRatioWidth * normalizedAspectRatioHeight; + let naturalCropWidth = Math.floor(imageWidth * (cropArea.width / 100) / normalizedAspectRatioWidth) * normalizedAspectRatioWidth; + let naturalCropHeight = naturalCropWidth / normalizedAspectRatioWidth * normalizedAspectRatioHeight; + + while (naturalCropHeight > imageHeight) { + // can't crop area larger than image itself, so keep subtracting normalized aspect ratio values until area is valid + naturalCropHeight -= normalizedAspectRatioHeight; + naturalCropWidth -= normalizedAspectRatioWidth; + } // modify cropArea with pixel snapping values cropArea.width = (naturalCropWidth / imageWidth) * 100;