From 8bc80d282120842ec9177121226e08abd39de3c0 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Tue, 21 May 2024 09:45:42 +0530 Subject: [PATCH] Merge --- web/apps/photos/src/services/face/f-index.ts | 21 +++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/web/apps/photos/src/services/face/f-index.ts b/web/apps/photos/src/services/face/f-index.ts index 7358e7753..53f2c41db 100644 --- a/web/apps/photos/src/services/face/f-index.ts +++ b/web/apps/photos/src/services/face/f-index.ts @@ -737,20 +737,17 @@ const extractFaceCrop = ( const paddedBox = roundBox(enlargeBox(alignmentBox, 1.5)); - return cropImage(imageBitmap, paddedBox, 256); -}; + const outputSize = { width: paddedBox.width, height: paddedBox.height }; -const cropImage = ( - imageBitmap: ImageBitmap, - box: Box, - maxDimension: number, -) => { - const outputSize = { width: box.width, height: box.height }; + const maxDimension = 256; + const scale = Math.min( + maxDimension / paddedBox.width, + maxDimension / paddedBox.height, + ); - const scale = Math.min(maxDimension / box.width, maxDimension / box.height); if (scale < 1) { - outputSize.width = Math.round(scale * box.width); - outputSize.height = Math.round(scale * box.height); + outputSize.width = Math.round(scale * paddedBox.width); + outputSize.height = Math.round(scale * paddedBox.height); } const offscreen = new OffscreenCanvas(outputSize.width, outputSize.height); @@ -766,7 +763,7 @@ const cropImage = ( height: outputSize.height, }); - const enlargedBox = enlargeBox(box, 1.5); + const enlargedBox = enlargeBox(paddedBox, 1.5); const enlargedOutputBox = enlargeBox(outputBox, 1.5); offscreenCtx.drawImage(