This page was machine-translated. Spotted a mistake?Help improve it.
Skip to content

AI Canvas Expand

使用 AI 驱动的填充(外绘)扩展图像画布。向任意方向延伸图像,并用与现有图像匹配的 AI 生成内容填充新区域。

API Endpoint

POST /api/v1/tools/image/ai-canvas-expand

处理方式: 异步(返回 202,通过 SSE 轮询 /api/v1/jobs/{jobId}/progress 获取状态)

模型包: object-eraser-colorize(1-2 GB)

Parameters

ParameterTypeRequiredDefaultDescription
filefile-图像文件(multipart)
extendTopinteger0顶部要扩展的像素数
extendRightinteger0右侧要扩展的像素数
extendBottominteger0底部要扩展的像素数
extendLeftinteger0左侧要扩展的像素数
tierstring"balanced"质量档位:fastbalancedhigh
formatstring"auto"输出格式:autopngjpgjpegwebptiffgifavifheicheifjxl
qualityinteger95输出质量(1-100)

至少有一个扩展方向必须大于 0。

Example Request

bash
curl -X POST http://localhost:1349/api/v1/tools/image/ai-canvas-expand \
  -F "[email protected]" \
  -F 'settings={"extendTop":200,"extendBottom":200,"extendLeft":100,"extendRight":100,"tier":"balanced"}'

Response

Initial Response (202 Accepted)

json
{
  "jobId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "async": true
}

Progress (SSE at /api/v1/jobs/{jobId}/progress)

event: progress
data: {"phase":"processing","stage":"Expanding canvas...","percent":50}

Final Result (via SSE)

json
{
  "phase": "complete",
  "percent": 100,
  "result": {
    "jobId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "downloadUrl": "/api/v1/download/{jobId}/photo_extended.png",
    "previewUrl": "/api/v1/download/{jobId}/preview.webp",
    "originalSize": 300000,
    "processedSize": 520000
  }
}

Notes

  • 需要安装 object-eraser-colorize 模型包(1-2 GB)。
  • 使用基于 LaMa 的外绘为扩展区域生成内容。
  • tier 参数在速度和质量之间权衡:fast 能快速产出结果但可能有瑕疵,high 耗时更长但能产出更平滑、更连贯的填充。
  • 扩展值以像素为单位。最终图像尺寸将为:原始宽度 + extendLeft + extendRight 乘以 原始高度 + extendTop + extendBottom。
  • 对于浏览器无法预览的输出格式(HEIC、JXL、TIFF),会在主输出旁生成一个 WebP 预览。
  • 通过自动解码支持 HEIC/HEIF、RAW、TGA、PSD、EXR 和 HDR 输入格式。