Files
membank/.trae/skills/image-tools/SKILL.md
12600k-rog-d4 62a216299c 0711
2026-07-11 21:06:00 +08:00

172 lines
7.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
基于火山引擎 Ark API 的 Doubao Seedream 模型,支持文生图、图生图、多图融合、图片编辑。官方文档:[Seedream 4.0-5.0 教程](https://www.volcengine.com/docs/82379/1548482)
## 前提条件
- `curl.exe`Windows内置
- Ark API Key: `ark-119a37ed-f123-42fc-aea6-b38d47d47fc0-f7ddf`
- API端点: `https://ark.cn-beijing.volces.com/api/v3/images/generations`
## 模式一览
| 模式 | `image`参数 | 用途 |
|---|---|---|
| 文生图 | 省略或`[]` | 从文字描述生成图片 |
| 图生图 | `["url1"]` | 基于参考图生成新图通过prompt控制保留原图产品外观 |
| 多图融合 | `["url1","url2",...]` | 最多14张参考图融合prompt中用"图1/图2"指代 |
默认模型: `doubao-seedream-5-0-260128`5.0支持4K、png输出、联网搜索
## 图生图核心技巧
Seedream 的 `image` 参数传入的是**参考图**,模型会根据 prompt 重新生成图片。通过精确的 prompt 可以较好地保持产品形态,但**不能做到像素级100%一致**。
**产品外观保持模板**(来自官方文档验证有效):
> `"严格保持图1中U盘产品的整体外观、形状、颜色、尺寸比例和所有可见细节完全不变。在此前提下仅更换背景和场景将产品放置在XXX场景中..."`
关键:**先锁定"完全不变",再用"在此前提下,仅更换..."描述新场景**。
## Prompt 结构(官方推荐)
遵循 **主体 + 行为 + 环境 + 风格** 结构建议不超过300个汉字
- **主体**: 产品是什么(用"图1"指代参考图)
- **行为**: 产品在做什么/处于什么状态
- **环境**: 背景、场景描述
- **风格**: 光照、色彩、构图、氛围
## 文字渲染技巧
Seedream 5.0 文字渲染精度 99%+。关键写法:
- **双引号包裹**:双引号内文字有特殊渲染优先级,`标题"NAS U盘"` 远优于 `标题NAS U盘`
- **指定字体形态**:明确"白色加粗无衬线大号字体"、"黑色加粗印刷体",避免模糊描述
- **清晰度约束**:加"所有文字笔画清晰醒目、无乱码无模糊"
- **控制文字量**:避免过多小字;功能标签用稍大字号并逐一指定位置,如 `画面底部水平排列四个标签,白色中号粗体分别显示"秒变NAS""远程访问""自动备份""私有云盘"`
## 文生图Windows PowerShell
```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
```powershell
$imgBytes = [System.IO.File]::ReadAllBytes((Resolve-Path "path\to\input.png"))
$imgBase64 = [System.Convert]::ToBase64String($imgBytes)
$tmpFile = "$env:TEMP\request.json"
$sw = [System.IO.StreamWriter]::new($tmpFile, $false, (New-Object System.Text.UTF8Encoding $false))
$sw.WriteLine('{')
$sw.WriteLine(' "model": "doubao-seedream-5-0-260128",')
$sw.WriteLine(' "prompt": "严格保持图1中产品的外观和形态完全不变在此前提下仅更换背景为白色",')
$sw.WriteLine(' "image": ["data:image/png;base64,' + $imgBase64 + '"],')
$sw.WriteLine(' "size": "2K",')
$sw.WriteLine(' "output_format": "png",')
$sw.WriteLine(' "response_format": "url",')
$sw.WriteLine(' "stream": false,')
$sw.WriteLine(' "watermark": false,')
$sw.WriteLine(' "optimize_prompt_options": { "mode": "standard" }')
$sw.WriteLine('}')
$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
```
> 当 prompt 中包含中文引号等特殊字符时,不要用 `@"..."@` here-string 拼接 JSON改用 `StreamWriter.WriteLine()` 逐行写入。
## 多图融合
```json
{
"model": "doubao-seedream-5-0-260128",
"prompt": "把图1的人物穿上图2的衣服站在图3的场景中",
"image": ["url1", "url2", "url3"],
"size": "2K",
"output_format": "png",
"response_format": "url",
"stream": false,
"watermark": false
}
```
## Seedream 参数参考
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| `model` | string | 是 | `doubao-seedream-5-0-260128`5.0,推荐)、`doubao-seedream-5-0-lite-260128`5.0 Lite`doubao-seedream-4-5-251128`4.5)、`doubao-seedream-4-0-250828`4.0 |
| `prompt` | string | 是 | 文本提示词最多约300汉字或600英文词。建议按「主体+行为+环境+风格」结构组织 |
| `image` | string[] | 否 | 参考图片URL或Base64**最多14张**prompt中用"图1/图2"指代。输入+输出总数 ≤ 15 |
| `size` | string | 否 | `2K`(默认)、`3K`仅5.0)、`4K`5.0/4.5/4.0)。推荐用别名(官方文档验证效果更好) |
| `response_format` | string | 否 | `url`下载链接24h有效`b64_json` |
| `output_format` | string | 否 | `png`仅5.0支持)或 `jpeg`(默认) |
| `optimize_prompt_options` | object | 否 | `{ "mode": "standard" }` 开启提示词优化提升生图质量5.0/4.5仅支持standard |
| `sequential_image_generation` | string | 否 | `disabled`(单图)或 `auto`(组图) |
| `sequential_image_generation_options` | object | 否 | `{ "max_images": N }` N为1-15 |
| `stream` | boolean | 否 | `false`(等待全部)或 `true`(逐张返回) |
| `watermark` | boolean | 否 | 默认`true`**建议设`false`** |
| `tools` | array | 否 | `[{ "type": "web_search" }]` 联网搜索仅5.0 |
## 尺寸指南
| 别名 | 5.0 | 4.5 | 4.0 | 适用场景 |
|---|---|---|---|---|
| `2K` | 2048px | 2048px | 2048px | 默认,质量与速度平衡 |
| `3K` | 3072px | — | — | 高质量产品图 |
| `4K` | 4096px | 4096px | 4096px | 最终生产级质量 |
推荐用别名(如`2K`)而非像素值,模型会自行判断最优分辨率。两种方式不可混用。
## 提示词技巧
- **场景描述**: 主体、动作、环境、氛围
- **风格词**: "电商商品主图风格"、"电影大片感"、"oc渲染"、"超现实主义"
- **质量词**: "柔和自然光布光"、"光线追踪"、"景深"
- **图生图**: 开头用"严格保持图1中产品的整体外观...完全不变。在此前提下,仅..."锁定产品形态
- **文字**: 用双引号包裹所有文字内容如`标题"NAS U盘"`,逐一指定位置和字号,加清晰度约束
- **中文原生支持** — 无需翻译
## Windows注意事项
| 问题 | 解决方案 |
|---|---|
| JSON UTF-8 BOM | 用 `[System.IO.StreamWriter]::new($path, $false, (New-Object System.Text.UTF8Encoding $false))` |
| curl引号问题 | 写JSON到临时文件`-d "@$tmpFile"` |
| 中文引号/特殊字符 | 用 `StreamWriter.WriteLine()` 逐行写,不要用 here-string |
| curl别名冲突 | 用 `curl.exe` 而非 `curl` |
| 续行符 | 用反引号 `` ` `` |
## 错误处理
- **401**: API Key无效
- **400**: 检查提示词长度、图片格式、尺寸值像素不低于3686400
- **429**: 限流,等待后重试
- **500**: 服务器错误,稍后重试