exception handling
parent
ec6f4f8547
commit
a4646a2389
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue