This commit is contained in:
李志鹏
2026-01-21 13:37:50 +08:00
parent 2fad680490
commit 750d90ee0b
4 changed files with 29 additions and 22 deletions

View File

@@ -2208,8 +2208,13 @@ export const resizeImage = async (base64, width, height) => {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const scale = height / img.height;
const w = img.width * scale;
const h = img.height * scale;
const x = (width - w) / 2;
const y = 0;
const ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, width, height);
ctx.drawImage(img, x, y, w, h);
resolve(canvas.toDataURL());
};
img.onerror = reject;