Remove round
authorCyperghost <olaf_schmitz_1@t-online.de>
Wed, 18 Dec 2024 08:01:47 +0000 (09:01 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Wed, 18 Dec 2024 08:01:47 +0000 (09:01 +0100)
Limit to max width and height

ts/WoltLabSuite/Core/Component/Image/Cropper.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Component/Image/Cropper.js

index 0df7481033896ab75dd55b8e9629ebb52778184d..8212edbefeb3d0a1385899c05f4464a9927a76ef 100644 (file)
@@ -222,10 +222,10 @@ abstract class ImageCropper {
       const maxHeight = maxWidth / this.configuration.aspectRatio;
 
       if (
-        Math.round(selection.width) < minWidth ||
-        Math.round(selection.height) < minHeight ||
-        Math.round(selection.width) > maxWidth ||
-        Math.round(selection.height) > maxHeight
+        selection.width < minWidth ||
+        selection.height < minHeight ||
+        selection.width > maxWidth ||
+        selection.height > maxHeight
       ) {
         event.preventDefault();
       }
@@ -260,8 +260,8 @@ abstract class ImageCropper {
     this.cropperSelection!.$change(
       0,
       0,
-      this.maxSize.width * selectionRatio,
-      this.maxSize.height * selectionRatio,
+      Math.min(this.cropperCanvasRect.width, this.maxSize.width * selectionRatio),
+      Math.min(this.cropperCanvasRect.height, this.maxSize.height * selectionRatio),
       this.configuration.aspectRatio,
       true,
     );
index 046b13b6cdfd201a9bb8ebbf91bce81dd7dfbbd4..06c2cf3796899abde816d68a2f929196731a98da 100644 (file)
@@ -165,10 +165,10 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Image/Resizer", "WoltL
                 const maxWidth = this.cropperCanvasRect.width;
                 const minHeight = minWidth / this.configuration.aspectRatio;
                 const maxHeight = maxWidth / this.configuration.aspectRatio;
-                if (Math.round(selection.width) < minWidth ||
-                    Math.round(selection.height) < minHeight ||
-                    Math.round(selection.width) > maxWidth ||
-                    Math.round(selection.height) > maxHeight) {
+                if (selection.width < minWidth ||
+                    selection.height < minHeight ||
+                    selection.width > maxWidth ||
+                    selection.height > maxHeight) {
                     event.preventDefault();
                 }
             });
@@ -188,7 +188,7 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Image/Resizer", "WoltL
             this.cropperImage.$center("contain");
             this.cropperCanvasRect = this.cropperImage.getBoundingClientRect();
             const selectionRatio = Math.min(this.cropperCanvasRect.width / this.maxSize.width, this.cropperCanvasRect.height / this.maxSize.height);
-            this.cropperSelection.$change(0, 0, this.maxSize.width * selectionRatio, this.maxSize.height * selectionRatio, this.configuration.aspectRatio, true);
+            this.cropperSelection.$change(0, 0, Math.min(this.cropperCanvasRect.width, this.maxSize.width * selectionRatio), Math.min(this.cropperCanvasRect.height, this.maxSize.height * selectionRatio), this.configuration.aspectRatio, true);
             this.cropperSelection.$center();
             this.cropperSelection.scrollIntoView({ block: "center", inline: "center" });
         }