This commit is contained in:
Manav Rathi 2024-05-21 09:45:42 +05:30
parent 825f5ff88d
commit 8bc80d2821
No known key found for this signature in database

View file

@ -737,20 +737,17 @@ const extractFaceCrop = (
const paddedBox = roundBox(enlargeBox(alignmentBox, 1.5)); const paddedBox = roundBox(enlargeBox(alignmentBox, 1.5));
return cropImage(imageBitmap, paddedBox, 256); const outputSize = { width: paddedBox.width, height: paddedBox.height };
};
const cropImage = ( const maxDimension = 256;
imageBitmap: ImageBitmap, const scale = Math.min(
box: Box, maxDimension / paddedBox.width,
maxDimension: number, maxDimension / paddedBox.height,
) => { );
const outputSize = { width: box.width, height: box.height };
const scale = Math.min(maxDimension / box.width, maxDimension / box.height);
if (scale < 1) { if (scale < 1) {
outputSize.width = Math.round(scale * box.width); outputSize.width = Math.round(scale * paddedBox.width);
outputSize.height = Math.round(scale * box.height); outputSize.height = Math.round(scale * paddedBox.height);
} }
const offscreen = new OffscreenCanvas(outputSize.width, outputSize.height); const offscreen = new OffscreenCanvas(outputSize.width, outputSize.height);
@ -766,7 +763,7 @@ const cropImage = (
height: outputSize.height, height: outputSize.height,
}); });
const enlargedBox = enlargeBox(box, 1.5); const enlargedBox = enlargeBox(paddedBox, 1.5);
const enlargedOutputBox = enlargeBox(outputBox, 1.5); const enlargedOutputBox = enlargeBox(outputBox, 1.5);
offscreenCtx.drawImage( offscreenCtx.drawImage(