Home > PCB_ImageTool > processImage
PCB_ImageTool.processImage() method
This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Warning: This API is now obsolete.
临时接口(插入图片 PCB 迁移打通流程用):等统一放置接口重构落地后删除替换,请尽快迁移,勿在新功能中继续依赖
选图处理门面(弹窗内重选图片:校验/压缩/读尺寸/预览 dataURL 全由服务端完成)
Signature
typescript
function processImage(
file: File,
options?: { maxBytes?: number; acceptableBytes?: number },
): Promise<{ file: File; dataURL: string; width: number; height: number; msg: string | null }>;1
2
3
4
2
3
4
Parameters
Parameter | Type | Description |
|---|---|---|
file | File | 弹窗内重选 |
options | { maxBytes?: number; acceptableBytes?: number } | (Optional) .acceptableBytes - 可接受大小(超过则压缩),默认 2M |
Returns
Promise<{ file: File; dataURL: string; width: number; height: number; msg: string | null }>
处理结果:file 压缩后文件;dataURL 预览图 dataURL(decode 失败为空字符串);width/height 原始自然尺寸;msg 提示消息(有值需 toast,如「不能超过 50MB」「已压缩至小于2MB」)
Remarks
ADD since EDA v5
Example
javascript
// 弹窗内重选图片:选择 → 处理 → 更新预览
const file = await eda.sys_FileSystem.openReadFileDialog(['.png', '.jpg']);
if (!file) {
return;
}
const res = await eda.pcb_ImageTool.processImage({ file });
if (res.msg) {
eda.sys_ToastMessage.showMessage(eda.sys_I18n.text(res.msg));
}
if (res.dataURL) {
// 更新预览:res.dataURL(图)、res.width/res.height(原始尺寸)
console.log('图片已就绪:', res.file.name, res.width, res.height);
}1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13