Files
codex-market-app/gen-image/README.md
T

56 lines
2.1 KiB
Markdown
Raw Normal View History

2026-07-14 17:53:43 +08:00
# gen-image · 生图 Skill
2026-07-18 11:00:23 +08:00
通过大模型中转站,直接调用 OpenAI 图片接口生图。文生图 / 图生图 / 局部重绘 / 透明背景 / 1K-4K 常用尺寸 / 可选 style 风格参数,零第三方依赖。
2026-07-14 17:53:43 +08:00
## 快速开始
```bash
# 1. 配置凭证
cp .env.example .env
# 编辑 .env,填入 IMAGE_API_BASE_URL、IMAGE_API_KEY
# 2. 文生图
python3 scripts/gen_image.py "a cozy cabin in snowy mountains, golden hour, cinematic" \
2026-07-18 11:00:23 +08:00
--size 2k-landscape --quality high
2026-07-14 17:53:43 +08:00
# 3. 图生图 / 编辑
2026-07-18 11:00:23 +08:00
python3 scripts/gen_image.py "把背景换成星空" --edit input.png --size 1k-square
2026-07-14 17:53:43 +08:00
# 4. 局部重绘(mask 透明处为重绘区域)
python3 scripts/gen_image.py "戴上一顶红帽子" --edit input.png --mask mask.png
2026-07-18 11:00:23 +08:00
# 5. 可选 style 参数(部分模型/中转支持)
python3 scripts/gen_image.py "a studio portrait, natural light" --style natural --size 1k-portrait
2026-07-14 17:53:43 +08:00
```
图片保存到 `output/`,脚本打印完整路径。
## 配置项(.env)
| 变量 | 说明 |
|------|------|
| `IMAGE_API_BASE_URL` | 中转站基址,如 `https://your-relay.com`(自动补 `/v1/images/...`) |
| `IMAGE_API_KEY` | 中转站 API Key |
| `IMAGE_MODEL` | 默认模型,默认 `gpt-image-2`,可用 `--model` 覆盖 |
## 参数
2026-07-18 11:00:23 +08:00
`--size` `--n` `--quality` `--background transparent` `--style` `--edit`(可多次) `--mask` `--model` `--output`
2026-07-14 17:53:43 +08:00
详见 `python3 scripts/gen_image.py --help` 与 `SKILL.md`。
2026-07-18 11:00:23 +08:00
## 尺寸与风格
`--size` 支持直接传像素值,也支持别名:
| 规格 | 常用别名 |
|------|----------|
| 1K | `1k-square`、`1k-landscape`、`1k-portrait` |
| 2K | `2k-square`、`2k-landscape`、`2k-portrait`、`2k-wide`、`2k-tall` |
| 4K | `4k-square`、`4k-landscape`、`4k-portrait`、`4k-wide`、`4k-tall`、`4k-uhd`、`4k-uhd-portrait` |
风格优先写进 prompt;目标模型或中转明确支持独立风格字段时,可额外传 `--style natural`、`--style vivid`、`--style anime`、`--style photorealistic` 等。
2026-07-14 17:53:43 +08:00
## 安全
`.env` 与 `output/` 已在 `.gitignore` 中,不会提交。切勿把 API Key 写进代码或对话。