控制导出图片大小
This commit is contained in:
@@ -2191,3 +2191,27 @@ export const imageModeHandler = ({ imageMode, newImage, canvasWidth, canvasHeigh
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 调整图像大小
|
||||
* @param {string} base64 - 原始base64字符串
|
||||
* @param {number} width - 目标宽度
|
||||
* @param {number} height - 目标高度
|
||||
* @returns {Promise<string>} 处理后的base64字符串
|
||||
*/
|
||||
export const resizeImage = async (base64, width, height) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const img = new Image();
|
||||
img.src = base64;
|
||||
img.onload = () => {
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
const ctx = canvas.getContext("2d");
|
||||
ctx.drawImage(img, 0, 0, width, height);
|
||||
resolve(canvas.toDataURL());
|
||||
};
|
||||
img.onerror = reject;
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user