generate-image
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesegenerate-image: images for coding agents, handed back into the chat
generate-image:为 coding agents 生成图片,并返回到聊天中
Generate production-ready imagery while you build, then show it to the user.
Images are saved straight into the project as exact-size //.
.webp.png.jpg在构建过程中生成可用于生产环境的图像,然后向用户展示。
图像会以精确尺寸直接保存到项目中,格式为 //。
.webp.png.jpgBackends: who actually makes the pixels
后端:究竟由谁生成像素
| Backend | What it is | Cost | Needs |
|---|---|---|---|
| Codex CLI's built-in | the user's ChatGPT plan | |
| FLUX.1-schnell via mflux | free, offline | Apple Silicon Mac, ~7 GB one-time model download |
| hosted APIs | per image, on the user's API account | a key stored with |
--backend autocodexlocalcodex exec~/.codex/generated_images/| 后端 | 是什么 | 费用 | 所需条件 |
|---|---|---|---|
| Codex CLI 内置的 | 用户的 ChatGPT 套餐 | 已安装 |
| 通过 mflux 使用 FLUX.1-schnell | 免费、离线 | Apple Silicon Mac、一次性下载约 7 GB 模型 |
| 托管 API | 按张计费,使用用户的 API 账户 | 使用 |
--backend autocodexlocalcodex exec~/.codex/generated_images/When to use and when NOT to
何时使用,何时不要使用
Generate: hero images, section backgrounds, textures, spot illustrations,
og:images (1200x630), product/editorial photography, empty-state art,
transparent cut-outs, and edits or variations of an existing image.
Don't generate: logos, icons, and UI screenshots. Use SVG for logos and
icons, and real screenshots for UI. On a short headline in the image
renders well. On (FLUX), keep legible text to 1–2 words at most. In
both cases, put real page copy in HTML/CSS over the image.
codexlocal生成: 主视觉图、区块背景、纹理、局部插画、
og:images(1200x630)、产品/编辑类摄影、空状态插图、
透明背景抠图,以及对现有图像的编辑或变体。
不要生成: logo、图标和 UI 截图。Logo 和
图标应使用 SVG,UI 应使用真实截图。在 后端中,图像里的短标题
渲染效果很好。在 (FLUX)后端中,清晰可辨的文字最多只保留 1–2 个词。
两种情况下,都应将真实的页面文案通过 HTML/CSS 叠加在图像上。
codexlocalSetup: do this first (once per session)
设置:每个会话先执行一次
bash
python3 <SKILL_DIR>/scripts/doctor.pyIt needs only the system . Act on what it reports; don't make the
user troubleshoot:
python3- /
! Codex CLI not installed: if the user has a ChatGPT plan, this is the best backend. Offernot signed in with ChatGPT. The sign-in (npm install -g @openai/codex) opens a browser, so the user runs it themselves.codex login - : offer
✗ uv is not installed(orbrew install uv), then re-run the doctor.curl -LsSf https://astral.sh/uv/install.sh | sh - Local-only items (,
platform,disk) only matter formodel not downloaded. When Codex is ready they are advisory.--backend local
When it says "Ready to generate", go ahead. The doctor also prints the backend
will use.
autobash
python3 <SKILL_DIR>/scripts/doctor.py它只需要系统 。根据它的报告采取相应措施;不要让用户自行排查
问题:
python3- /
! Codex CLI not installed:如果用户 有 ChatGPT 套餐,这是最佳后端。建议执行not signed in with ChatGPT。登录(npm install -g @openai/codex)会打开浏览器,因此必须由用户 自行运行。codex login - :建议执行
✗ uv is not installed(或brew install uv),然后重新运行 doctor。curl -LsSf https://astral.sh/uv/install.sh | sh - 仅限本地的事项(、
platform、disk)仅在model not downloaded时才需要关注。Codex 就绪后,这些信息仅供参考。--backend local
当它显示“Ready to generate”后,即可继续。doctor 还会打印 将要使用的
后端。
autoHow to run: in the background
如何运行:在后台执行
The script lives in THIS skill's directory, not the user's project:
bash
uv run <SKILL_DIR>/scripts/generate.py "PROMPT" --out public/hero.webp --size 1440x800 --jsonRun it as a background task. If you have a background option (Claude
Code: Bash with ), use it. You'll be notified when it
exits, so keep working meanwhile and don't poll. Timing: takes ~30–60 s
per image; takes ~40–90 s, plus several minutes for the ~7 GB model on
first use. If you must run it in the foreground, set the timeout to at least
10 minutes.
run_in_background: truecodexlocal--json{"path": "/abs/public/hero.webp", "width": 1440, "height": 800, "seed": 1, "backend": "codex"}脚本位于此 Skill 的目录中,而不是用户的项目中:
bash
uv run <SKILL_DIR>/scripts/generate.py "PROMPT" --out public/hero.webp --size 1440x800 --json将其作为后台任务运行。 如果你有后台运行选项(Claude
Code:使用 的 Bash),请使用它。任务退出时会收到
通知,因此可以继续处理其他工作,不要轮询。耗时: 每张图约
30–60 秒; 每张约 40–90 秒,首次使用还需几分钟下载约 7 GB 的模型。
如果必须在前台运行,请将超时设置为至少 10 分钟。
run_in_background: truecodexlocal--json{"path": "/abs/public/hero.webp", "width": 1440, "height": 800, "seed": 1, "backend": "codex"}Hand the image back: always do both
将图像交回:始终执行两项操作
- Look at it yourself. Read the image file before wiring it into the page. If it's wrong, regenerate with a more concrete prompt; don't ship unseen images.
- Show it to the user in the chat. Don't leave a path buried in tool
output. Use the best option the environment has:
- A tool that sends or renders files to the user (in the Claude desktop
app: with
SendUserFile). This shows the image inline, the way Codex does. Prefer this whenever it exists.display: "render" - Otherwise put a markdown image in your reply,
, and the plain absolute path. Orcha and most IDE chats turn the path into a clickable link.
 - Terminal-only: opens results in Preview, and
--open(iTerm2) orimgcat <path>(Kitty/Ghostty/WezTerm) render inline.kitten icat <path>
- A tool that sends or renders files to the user (in the Claude desktop
app:
- 亲自查看图像。 在将图像接入页面前,先读取该图像文件。 如果图像有误,请使用更具体的提示词重新生成;不要交付未经查看的 图像。
- 在聊天中向用户展示。 不要把路径埋在工具输出中。请使用环境中
最佳的方式:
- 可向用户发送或渲染文件的工具(在 Claude 桌面应用中:使用
并设置
SendUserFile)。这会像 Codex 一样 内联展示图像。只要存在此工具,就优先使用。display: "render" - 否则,在回复中放入 Markdown 图像,
,并附上纯文本绝对路径。Orcha 和 大多数 IDE 聊天会将该路径转换为可点击链接。
 - 仅限终端:会在 Mac 默认查看器中打开结果,而
--open(iTerm2)或imgcat <path>(Kitty/Ghostty/WezTerm)会内联渲染。kitten icat <path>
- 可向用户发送或渲染文件的工具(在 Claude 桌面应用中:使用
Flags
参数
| Flag | Meaning |
|---|---|
| Output file; format from extension: |
| Exact output pixels, e.g. |
| |
| Real transparent background ( |
| Reference or edit-source image, repeatable ( |
| N candidates as |
| JSON array of |
| Machine-readable result line per image |
| Reproducible output on |
| Local FLUX tuning (advanced) |
| Ignore the project's |
| Open each result in the Mac's default viewer |
| Print the plan (styled prompts, sizes) without generating |
| 参数 | 含义 |
|---|---|
| 输出文件;格式由扩展名决定: |
| 精确的输出像素尺寸,例如 |
| |
| 真正的透明背景(仅 |
| 参考图或编辑源图,可重复指定(仅 |
| N 个候选图,命名为 |
| 包含 |
| 为每张图像输出一行机器可读的结果 |
| 在 |
| 调整本地 FLUX(高级用法) |
| 忽略项目的 |
| 在 Mac 默认查看器中打开每个结果 |
| 仅打印生成计划(带样式的提示词、尺寸),不生成图像 |
Workflow rules
工作流规则
- Plan all assets first, then generate them in one , in the background.
--batch - Generate 1–2 candidates, not 10. Each image uses the user's plan quota; each
codeximage costs about a minute.local - Always view, then show (see "Hand the image back").
- Record what you shipped in the commit message: the prompt, the backend, and the seed when the backend supports one.
- Set up style once: if the project has no , consider creating one (copy
imagegen.tomlfrom this skill's directory) so all assets share an art direction.imagegen.example.toml
- 先规划所有素材,再通过一次 统一生成, 并在后台执行。
--batch - 只生成 1–2 个候选方案,不要生成 10 个。 每张 图像都会 消耗用户套餐的配额;每张
codex图像约需一分钟。local - 务必先查看,再展示(参见“将图像交回”)。
- 在提交信息中记录交付内容:提示词、后端,以及后端支持时所用的 seed。
- **只设置一次风格:**如果项目没有 ,可考虑创建一个 (从此 Skill 的目录复制
imagegen.toml),让所有素材共享统一的 艺术方向。imagegen.example.toml
Writing good prompts
如何编写优质提示词
Both backends reward specific, concrete descriptions and punish one-word
prompts. Every prompt should cover:
- Subject: the concrete thing ("handmade ceramic bowls", not "something nice")
- Setting: where it is and what surrounds it
- Lighting: direction and quality ("soft morning light from the left")
- Mood and palette: the feeling and the colors
- Composition: framing and negative space, especially where text will overlay ("subject on the right third, empty space on the left for a headline")
On , a short labeled spec works especially well. This is the format
Codex's own image skill uses:
codextext
Use case: product-mockup
Asset type: landing page hero
Primary request: a ceramic coffee mug on a linen tablecloth
Style/medium: clean product photography
Composition/framing: wide, mug on the right third, empty space on the left for copy
Lighting/mood: soft window light, calm morning
Constraints: no logos, no watermarkFor edits with , list what must stay the same ("change only the
background; keep the product and its edges unchanged").
--refWeak → strong:
❌✅a coffee shopwarm natural-light photograph of a cozy independent coffee shop interior at golden hour, exposed brick walls, a barista blurred in the background, steam rising from a cup in the foreground, shallow depth of field, inviting mood
两种后端都偏好具体、明确的描述,并会“惩罚”过于简短的单词式提示词。每个提示词都应涵盖:
- 主体:具体事物(“手工陶瓷碗”,而不是“好看的东西”)
- 环境:事物所在的位置及周围环境
- 光线:方向和质感(“从左侧照来的柔和晨光”)
- 氛围和配色:感觉与颜色
- 构图:取景和留白,尤其是文字将要叠加的位置(“主体位于右侧三分 之一,左侧留出用于标题的空白”)
在 后端中,采用简短且带标签的规格尤其有效。Codex 自带的图像
Skill 使用以下格式:
codextext
Use case: product-mockup
Asset type: landing page hero
Primary request: a ceramic coffee mug on a linen tablecloth
Style/medium: clean product photography
Composition/framing: wide, mug on the right third, empty space on the left for copy
Lighting/mood: soft window light, calm morning
Constraints: no logos, no watermark使用 进行编辑时,请列出必须保持不变的内容(“仅更改背景;保持产品及其边缘不变”)。
--ref弱 → 强:
❌✅一间咖啡馆黄金时段下独立咖啡馆内部温暖自然的实景照片,裸露的砖墙,背景中虚化的咖啡师,前景杯中升起热气,浅景深,氛围温馨
Choosing dimensions: always set --size
deliberately
--size选择尺寸:始终明确设置 --size
--size| Asset | Size |
|---|---|
| Full-width hero | |
| Wide banner strip | |
| Section background | |
| og:image / social card | |
| Square spot illustration | |
| Portrait / mobile hero | |
| 素材 | 尺寸 |
|---|---|
| 全宽主视觉图 | |
| 宽幅横幅条 | |
| 区块背景 | |
| og:image / 社交卡片 | |
| 方形局部插画 | |
| 竖版/移动端主视觉图 | |
Hosted API keys (optional)
托管 API key(可选)
Only needed for , , or . The user stores a key
once at a hidden prompt; never ask them to paste a key into the chat:
openaigeminireplicatebash
uv run <SKILL_DIR>/scripts/generate.py --set-key openai # or: gemini, replicateThe key goes into the macOS Keychain, and the CLI reads it at run time. This
command refuses to run non-interactively, so you can't run it for them.
shows which providers have a key;
removes one.
--list-keys--delete-key <provider>仅在使用 、 或 时需要。用户只需在隐藏输入提示中
存储一次 key;绝不要要求用户将 key 粘贴到聊天中:
openaigeminireplicatebash
uv run <SKILL_DIR>/scripts/generate.py --set-key openai # or: gemini, replicatekey 将保存到 macOS Keychain,CLI 会在运行时读取。该
命令拒绝以非交互方式运行,因此你无法代替用户执行。
显示哪些提供商已配置 key;
用于删除 key。
--list-keys--delete-key <provider>Reference
参考
See in this skill's directory for per-asset-type
prompt recipes (hero, texture, illustration, og:image, photography).
reference/prompting.md有关各类素材的提示词配方(主视觉图、纹理、插画、og:image、摄影),请参阅此
Skill 目录中的 。
reference/prompting.md