exception handling
parent
ec6f4f8547
commit
a4646a2389
|
@ -47,9 +47,7 @@ export async function extractFaces(
|
||||||
x, y, width, height,
|
x, y, width, height,
|
||||||
}) => {
|
}) => {
|
||||||
const faceImg = createCanvas({ width, height });
|
const faceImg = createCanvas({ width, height });
|
||||||
try {
|
if (width > 0 && height > 0) getContext2dOrThrow(faceImg).putImageData(ctx.getImageData(x, y, width, height), 0, 0);
|
||||||
getContext2dOrThrow(faceImg).putImageData(ctx.getImageData(x, y, width, height), 0, 0);
|
|
||||||
} catch { /**/ }
|
|
||||||
return faceImg;
|
return faceImg;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ export function imageToSquare(input: HTMLImageElement | HTMLCanvasElement, input
|
||||||
const offset = Math.abs(width - height) / 2;
|
const offset = Math.abs(width - height) / 2;
|
||||||
const dx = centerImage && width < height ? offset : 0;
|
const dx = centerImage && width < height ? offset : 0;
|
||||||
const dy = centerImage && height < width ? 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;
|
return targetCanvas;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue