Files
membank/.trae/skills/image-tools/SKILL.md

8.8 KiB
Raw Blame History

name, description
name description
image-tools AI图片生成与编辑工具集。包含豆包万相Doubao Seedream和阿里云万相2.7两个AI图片引擎支持文生图、图生图、多图融合、图片编辑。用于生成产品主图、场景图、电商素材、宣传页等。Invoke when user needs to generate, edit, or transform images for e-commerce or product visuals.

Image Tools - AI图片生成与编辑工具集

集成两个AI图片引擎

  1. 豆包万相Doubao Seedream — 火山引擎Ark API支持文生图、图生图、多图融合、图片编辑、批量生成
  2. 阿里云万相2.7 — 阿里云百炼 wan2.7-image-pro支持文生图、图生图、图片编辑

引擎1豆包万相Doubao Seedream

使用火山引擎 Ark API 的 Doubao Seedream 模型,支持文生图、图生图、多图融合、图片编辑。

前提条件

  • curl.exeWindows内置
  • Ark API Key: ark-119a37ed-f123-42fc-aea6-b38d47d47fc0-f7ddf
  • API端点: https://ark.cn-beijing.volces.com/api/v3/images/generations

模式一览

模式 image参数 用途
文生图 省略或[] 从文字描述生成图片
图生图 ["url1"] 风格转换、精修、变换
多图融合 ["url1","url2",...] 最多14张参考图融合
图片编辑 ["url1"] + 编辑提示词 移除/替换元素、换背景等

默认模型: doubao-seedream-5-0-260128

文生图Windows PowerShell

$tmpFile = "$env:TEMP\request.json"
$prompt = "YOUR_PROMPT_HERE"
$json = @"
{"model":"doubao-seedream-5-0-260128","prompt":"$prompt","size":"2k","sequential_image_generation":"disabled","response_format":"url","stream":false,"watermark":false}
"@
$sw = [System.IO.StreamWriter]::new($tmpFile, $false, (New-Object System.Text.UTF8Encoding $false))
$sw.Write($json); $sw.Close()

$response = curl.exe -s -X POST https://ark.cn-beijing.volces.com/api/v3/images/generations `
  -H "Content-Type: application/json" `
  -H "Authorization: Bearer ark-119a37ed-f123-42fc-aea6-b38d47d47fc0-f7ddf" `
  -d "@$tmpFile" | ConvertFrom-Json

$imageUrl = $response.data[0].url
$outputPath = Join-Path (Get-Location) "output-name.png"
curl.exe -s -o $outputPath $imageUrl
Write-Output $outputPath

图生图/图片编辑本地文件输入Windows PowerShell

$imgBytes = [System.IO.File]::ReadAllBytes((Resolve-Path "path\to\input.png"))
$imgBase64 = [System.Convert]::ToBase64String($imgBytes)

$tmpFile = "$env:TEMP\request.json"
$prompt = "YOUR_EDIT_INSTRUCTIONS_HERE"
$json = @"
{"model":"doubao-seedream-5-0-260128","prompt":"$prompt","image":["data:image/png;base64,$imgBase64"],"size":"2k","sequential_image_generation":"disabled","response_format":"url","stream":false,"watermark":false}
"@
$sw = [System.IO.StreamWriter]::new($tmpFile, $false, (New-Object System.Text.UTF8Encoding $false))
$sw.Write($json); $sw.Close()

$response = curl.exe -s -X POST https://ark.cn-beijing.volces.com/api/v3/images/generations `
  -H "Content-Type: application/json" `
  -H "Authorization: Bearer ark-119a37ed-f123-42fc-aea6-b38d47d47fc0-f7ddf" `
  -d "@$tmpFile" | ConvertFrom-Json

$imageUrl = $response.data[0].url
$outputPath = Join-Path (Get-Location) "output-name.png"
curl.exe -s -o $outputPath $imageUrl
Write-Output $outputPath

多图融合

{
  "model": "doubao-seedream-5-0-260128",
  "prompt": "把图1的人物穿上图2的衣服站在图3的场景中",
  "image": ["url1", "url2", "url3"],
  "size": "2k",
  "sequential_image_generation": "disabled",
  "response_format": "url",
  "stream": false,
  "watermark": false
}

批量生成最多15张

{
  "model": "doubao-seedream-5-0-260128",
  "prompt": "一个女孩和她的布偶牛在过山车上,分别呈现早晨、中午、傍晚的场景",
  "sequential_image_generation": "auto",
  "sequential_image_generation_options": { "max_images": 3 },
  "size": "2k",
  "response_format": "url",
  "stream": false,
  "watermark": false
}

豆包参数参考

参数 类型 必填 说明
model string doubao-seedream-5-0-260128(默认)或 doubao-seededit-3-0-i2i(精确编辑)
prompt string 文本提示词,最多300中文字或600英文词
image string[] 参考图片URL或Base64data:image/png;base64,...最多14张
size string 2k(默认)、3k4kWIDTHxHEIGHT(如2048x1024),必须小写
response_format string url下载链接24h有效b64_json
sequential_image_generation string disabled(默认,单图)或 auto(模型决定批量数)
sequential_image_generation_options object { "max_images": N } N为1-15仅auto模式
stream boolean false(等待全部)或 true(逐张返回)
watermark boolean 添加"AI Generated"水印,默认false
guidance_scale float 文本遵循度(CFG),范围[1,10]仅seededit-3-0-i2i
seed int32 可复现种子仅seededit-3-0-i2i

豆包尺寸指南

别名 近似分辨率 适用场景
2k ~2048px 默认 — 质量与速度平衡
3k ~3072px 高质量,产品图
4k ~4096px 最终生产质量
WIDTHxHEIGHT 自定义 2048x1024宽幅横幅

像素约束:两个维度必须在[1280, 4096]最大3:1宽高比。

豆包提示词技巧

  • 描述场景: 主体、动作、环境、氛围
  • 指定风格: "电影大片感"、"水彩画风"、"赛博朋克"、"oc渲染"、"超现实主义"
  • 质量关键词: "光线追踪"、"景深"、"极致的光影"、"动态模糊"
  • 编辑指令: "把背景换成海滩"、"移除画面中的人物"、"将风格改为水彩画"
  • 中文提示词原生支持 — 无需翻译为英文

Windows注意事项

问题 解决方案
PowerShell 5.1给JSON加UTF-8 BOM 不要Set-Content[System.Text.Encoding]::UTF8,用[System.IO.StreamWriter]::new($path, $false, (New-Object System.Text.UTF8Encoding $false))
PowerShell破坏curl中的" 始终写JSON到临时文件-d "@$tmpFile"
curl别名冲突 curl.exe而非curl
续行符 用反引号`

豆包错误处理

  • 401: API Key无效 — 检查Authorization头
  • 400: 请求错误 — 检查提示词长度、图片格式、尺寸值
  • 429: 限流 — 等待后重试
  • 500: 服务器错误 — 稍后重试

精确编辑模型

需要精细编辑时,doubao-seededit-3-0-i2i提供额外控制:

{
  "model": "doubao-seededit-3-0-i2i",
  "prompt": "Change the dress color to red",
  "image": ["data:image/png;base64,..."],
  "guidance_scale": 5.5,
  "seed": 42,
  "size": "adaptive",
  "response_format": "url",
  "watermark": false
}

引擎2阿里云万相2.7

使用阿里云百炼 wan2.7-image-pro 模型,支持文生图、图生图、图片编辑。

前提条件

环境变量 DASHSCOPE_API_KEY 已配置默认使用内置Key

基本用法

python wan_image_edit.py <提示词> <输入图片> [输出路径] [尺寸]

参数说明

  • 提示词: 描述想要的效果,支持中英文
  • 输入图片: 产品图片路径PNG/JPG留空则为文生图
  • 输出路径: 输出文件名(可选,默认 wan_output.png
  • 尺寸: 1K 或 2K可选默认 2K

示例

# 白底产品图
python wan_image_edit.py "keep the product, pure white background, professional e-commerce photo" "product.png" "output.png"

# 场景图
python wan_image_edit.py "place product on modern desk, cozy home office" "product.png" "scene.png"

# 文生图(无输入图片)
python wan_image_edit.py "futuristic NAS server in data center" "" "t2i.png"

万相2.7可用尺寸

尺寸 分辨率 适用场景
1K 1024x1024 快速预览、轮播图
2K 2048x2048 主图、海报(推荐)

引擎选择建议

场景 推荐引擎 原因
电商产品主图 豆包万相 中文提示词支持好,风格丰富
场景图/氛围图 豆包万相 高质量渲染,支持多种风格
精细图片编辑 豆包万相(seededit) 专用编辑模型,精确控制
多图融合 豆包万相 原生支持最多14图融合
批量生成 豆包万相 一次请求最多15张
快速产品抠图/换背景 万相2.7 Python脚本调用便捷

输出规范

  • 保存图片到用户当前工作目录(或子目录)
  • API返回的URL 24小时内有效 — 立即下载保存到本地
  • 不要回读图片 — 用markdown显示: ![image](/absolute/path/to/image.png)
  • 只使用绝对路径
  • 不要在对话中重复路径