From 2b085290a4edc002079193146eb7608ee07a5173 Mon Sep 17 00:00:00 2001 From: Tom Richards Date: Sat, 21 Sep 2024 22:56:02 +0100 Subject: [PATCH] add `seedCropId` optional query param for the `/crop` endpoint for an image and use the dimensions to set the starting point of the crop --- kahuna/public/js/crop/controller.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kahuna/public/js/crop/controller.js b/kahuna/public/js/crop/controller.js index e8b7859ffd..0429e11cb7 100644 --- a/kahuna/public/js/crop/controller.js +++ b/kahuna/public/js/crop/controller.js @@ -78,12 +78,17 @@ crop.controller('ImageCropCtrl', [ ctrl.maxInputY = () => ctrl.originalHeight - ctrl.cropHeight(); + const maybeSeedCropId = $stateParams.seedCropId; + const [maybeSeedX1, maybeSeedY1, maybeSeedX2, maybeSeedY2] = maybeSeedCropId?.split("_") || []; + + // TODO attempt centering if seed crop dimensions don't fit + ctrl.coords = { - x1: ctrl.inputX, - y1: ctrl.inputY, + x1: maybeSeedX1 || ctrl.inputX, + y1: maybeSeedY1 || ctrl.inputY, // fill the image with the selection - x2: ctrl.originalWidth, - y2: ctrl.originalHeight + x2: maybeSeedX2 || ctrl.originalWidth, + y2: maybeSeedY2 || ctrl.originalHeight }; // If we have a square crop, remove any jitter introduced by client lib by using only one side