diff --git a/src/dom/extractFaces.ts b/src/dom/extractFaces.ts index 4220a69..a246183 100644 --- a/src/dom/extractFaces.ts +++ b/src/dom/extractFaces.ts @@ -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; }); } diff --git a/src/dom/imageToSquare.ts b/src/dom/imageToSquare.ts index 2d14744..d0fcfbf 100644 --- a/src/dom/imageToSquare.ts +++ b/src/dom/imageToSquare.ts @@ -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; }