diff --git a/resources/catalog.json b/resources/catalog.json index e371dc0..84c5c6e 100644 --- a/resources/catalog.json +++ b/resources/catalog.json @@ -68257,14 +68257,14 @@ "fields": [ { "key": "file_path", - "label": "图片地址", + "label": "源图片地址", "widget": "file", "type": "object", "displayType": "selectFile", "required": true, "defaultValue": "", "placeholder": "请输入或选择文件路径", - "description": "图片文件的完整路径,用于匹配或识别;点右侧按钮选择文件", + "description": "要被裁剪的源图片完整路径——本组件从已有图片文件中裁出区域,不是截屏;截屏请用「截图图像」组件", "advanced": false, "valueTypes": [ "rpa_str_file", @@ -68296,7 +68296,7 @@ "required": true, "defaultValue": "1", "placeholder": "请输入坐标点", - "description": "填写参数值,支持 ${变量} 引用上游输出", + "description": "裁剪区域左上角的 x 坐标(图片上的像素)", "advanced": false, "valueTypes": [ "rpa_int" @@ -68311,7 +68311,7 @@ "required": true, "defaultValue": "1", "placeholder": "请输入坐标点", - "description": "填写参数值,支持 ${变量} 引用上游输出", + "description": "裁剪区域右下角的 x 坐标,需大于起点 x", "advanced": false, "valueTypes": [ "rpa_int" @@ -68326,7 +68326,7 @@ "required": true, "defaultValue": "1", "placeholder": "请输入坐标点", - "description": "填写参数值,支持 ${变量} 引用上游输出", + "description": "裁剪区域左上角的 y 坐标(图片上的像素)", "advanced": false, "valueTypes": [ "rpa_int" @@ -68341,7 +68341,7 @@ "required": true, "defaultValue": "1", "placeholder": "请输入坐标点", - "description": "填写参数值,支持 ${变量} 引用上游输出", + "description": "裁剪区域右下角的 y 坐标,需大于起点 y", "advanced": false, "valueTypes": [ "rpa_int" diff --git a/src/main/capabilities/remaining-core.ts b/src/main/capabilities/remaining-core.ts index 61956d9..6f67b43 100644 --- a/src/main/capabilities/remaining-core.ts +++ b/src/main/capabilities/remaining-core.ts @@ -171,8 +171,13 @@ register("Image_Base64Decode", async (_ctx, _node, args) => { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, Buffer.from(value, "base64")); return file; }); register("Image_CropImg", async (_ctx, node, args) => { - const input = path.resolve(text(args, ["file_path", "imagePath", "path"])); const output = path.resolve(text(args, ["output"], input.replace(/(\.[^.]+)$/, "-crop$1"))); + const rawInput = text(args, ["file_path", "imagePath", "path"]); + if (!rawInput.trim()) throw new RuntimeError("validation_error", "图片地址不能为空", { nodeId: node.id, componentId: node.componentId, recommendation: "填写要裁剪的源图片完整路径(如 D:\\images\\shot.png),该组件是从已有图片文件里裁剪区域,不是截屏" }); + const input = path.resolve(rawInput); + if (!fs.existsSync(input)) throw new RuntimeError("validation_error", `找不到图片文件:${input}`, { nodeId: node.id, componentId: node.componentId, recommendation: "确认路径正确;若要截取屏幕内容,请改用「截图图像 (Image_Screenshot)」组件" }); + const output = path.resolve(text(args, ["output"], input.replace(/(\.[^.]+)$/, "-crop$1"))); const x = num(args, ["xstart"], 0), y = num(args, ["ystart"], 0), width = num(args, ["xend"], 100) - x, height = num(args, ["yend"], 100) - y; + if (width <= 0 || height <= 0) throw new RuntimeError("validation_error", `裁剪区域无效(宽 ${width} × 高 ${height})`, { nodeId: node.id, componentId: node.componentId, recommendation: "终点坐标需要大于起点坐标(单位是图片上的像素)" }); fs.mkdirSync(path.dirname(output), { recursive: true }); await powershell(`Add-Type -AssemblyName System.Drawing;$image=[System.Drawing.Image]::FromFile(${psString(input)});$rect=New-Object System.Drawing.Rectangle(${x},${y},${width},${height});$bitmap=New-Object System.Drawing.Bitmap($rect.Width,$rect.Height);$graphics=[System.Drawing.Graphics]::FromImage($bitmap);$graphics.DrawImage($image,New-Object System.Drawing.Rectangle(0,0,$rect.Width,$rect.Height),$rect,[System.Drawing.GraphicsUnit]::Pixel);$bitmap.Save(${psString(output)});$graphics.Dispose();$bitmap.Dispose();$image.Dispose()`); return output;