async function resizeImg(file: File, width: number, height: number) {
const img = await new Promise<HTMLImageElement | null>((resolve) => {
img.addEventListener("load", () => resolve(img));
img.addEventListener("error", () => resolve(null));
img.src = URL.createObjectURL(file);
const context = document.createElement("canvas").getContext("2d");
if (!img || !context) return null;
const { naturalWidth, naturalHeight } = img;
naturalWidth > naturalHeight
: Math.floor(naturalWidth * (height / naturalHeight));
naturalWidth > naturalHeight
? Math.floor(naturalHeight * (width / naturalWidth))
context.canvas.width = width;
context.canvas.height = height;
context.drawImage(img, 0, 0, width, height);
context.canvas.width = newWidth;
context.canvas.height = newHeight;
context.drawImage(img, 0, 0, newWidth, newHeight);
return await new Promise<Blob | null>((resolve) =>
context.canvas.toBlob(resolve, file.type),