exception handling

pull/39/head
Vladimir Mandic 2021-02-20 21:06:33 -05:00
parent ec6f4f8547
commit a4646a2389
2 changed files with 2 additions and 4 deletions

View File

@ -47,9 +47,7 @@ export async function extractFaces(
x, y, width, height,
}) => {
const faceImg = createCanvas({ width, height });
try {
getContext2dOrThrow(faceImg).putImageData(ctx.getImageData(x, y, width, height), 0, 0);
} catch { /**/ }
if (width > 0 && height > 0) getContext2dOrThrow(faceImg).putImageData(ctx.getImageData(x, y, width, height), 0, 0);
return faceImg;
});
}

View File

@ -21,7 +21,7 @@ export function imageToSquare(input: HTMLImageElement | HTMLCanvasElement, input
const offset = Math.abs(width - height) / 2;
const dx = centerImage && width < height ? offset : 0;
const dy = centerImage && height < width ? offset : 0;
getContext2dOrThrow(targetCanvas).drawImage(inputCanvas, dx, dy, width, height);
if (inputCanvas.width > 0 && inputCanvas.height > 0) getContext2dOrThrow(targetCanvas).drawImage(inputCanvas, dx, dy, width, height);
return targetCanvas;
}