Use when the user asks to generate or edit images via the OpenAI Image API (for example: generate image, edit/inpaint/mask, background removal or replacement, transparent background, product shots, concept art, covers, or batch variants); run the bundled CLI (`scripts/image_gen.py`) and require `OPENAI_API_KEY` for live calls.
Add this skill
npx mdskills install openai/imagegenComprehensive image generation skill with clear decision trees, augmentation rules, and taxonomy
1---2name: "imagegen"3description: "Use when the user asks to generate or edit images via the OpenAI Image API (for example: generate image, edit/inpaint/mask, background removal or replacement, transparent background, product shots, concept art, covers, or batch variants); run the bundled CLI (`scripts/image_gen.py`) and require `OPENAI_API_KEY` for live calls."4---567# Image Generation Skill89Generates or edits images for the current project (e.g., website assets, game assets, UI mockups, product mockups, wireframes, logo design, photorealistic images, infographics). Defaults to `gpt-image-1.5` and the OpenAI Image API, and prefers the bundled CLI for deterministic, reproducible runs.1011## When to use12- Generate a new image (concept art, product shot, cover, website hero)13- Edit an existing image (inpainting, masked edits, lighting or weather transformations, background replacement, object removal, compositing, transparent background)14- Batch runs (many prompts, or many variants across prompts)1516## Decision tree (generate vs edit vs batch)17- If the user provides an input image (or says “edit/retouch/inpaint/mask/translate/localize/change only X”) → **edit**18- Else if the user needs many different prompts/assets → **generate-batch**19- Else → **generate**2021## Workflow221. Decide intent: generate vs edit vs batch (see decision tree above).232. Collect inputs up front: prompt(s), exact text (verbatim), constraints/avoid list, and any input image(s)/mask(s). For multi-image edits, label each input by index and role; for edits, list invariants explicitly.243. If batch: write a temporary JSONL under tmp/ (one job per line), run once, then delete the JSONL.254. Augment prompt into a short labeled spec (structure + constraints) without inventing new creative requirements.265. Run the bundled CLI (`scripts/image_gen.py`) with sensible defaults (see references/cli.md).276. For complex edits/generations, inspect outputs (open/view images) and validate: subject, style, composition, text accuracy, and invariants/avoid items.287. Iterate: make a single targeted change (prompt or mask), re-run, re-check.298. Save/return final outputs and note the final prompt + flags used.3031## Temp and output conventions32- Use `tmp/imagegen/` for intermediate files (for example JSONL batches); delete when done.33- Write final artifacts under `output/imagegen/` when working in this repo.34- Use `--out` or `--out-dir` to control output paths; keep filenames stable and descriptive.3536## Dependencies (install if missing)37Prefer `uv` for dependency management.3839Python packages:40```41uv pip install openai pillow42```43If `uv` is unavailable:44```45python3 -m pip install openai pillow46```4748## Environment49- `OPENAI_API_KEY` must be set for live API calls.5051If the key is missing, give the user these steps:521. Create an API key in the OpenAI platform UI: https://platform.openai.com/api-keys532. Set `OPENAI_API_KEY` as an environment variable in their system.543. Offer to guide them through setting the environment variable for their OS/shell if needed.55- Never ask the user to paste the full key in chat. Ask them to set it locally and confirm when ready.5657If installation isn't possible in this environment, tell the user which dependency is missing and how to install it locally.5859## Defaults & rules60- Use `gpt-image-1.5` unless the user explicitly asks for `gpt-image-1-mini` or explicitly prefers a cheaper/faster model.61- Assume the user wants a new image unless they explicitly ask for an edit.62- Require `OPENAI_API_KEY` before any live API call.63- Use the OpenAI Python SDK (`openai` package) for all API calls; do not use raw HTTP.64- If the user requests edits, use `client.images.edit(...)` and include input images (and mask if provided).65- Prefer the bundled CLI (`scripts/image_gen.py`) over writing new one-off scripts.66- Never modify `scripts/image_gen.py`. If something is missing, ask the user before doing anything else.67- If the result isn’t clearly relevant or doesn’t satisfy constraints, iterate with small targeted prompt changes; only ask a question if a missing detail blocks success.6869## Prompt augmentation70Reformat user prompts into a structured, production-oriented spec. Only make implicit details explicit; do not invent new requirements.7172## Use-case taxonomy (exact slugs)73Classify each request into one of these buckets and keep the slug consistent across prompts and references.7475Generate:76- photorealistic-natural — candid/editorial lifestyle scenes with real texture and natural lighting.77- product-mockup — product/packaging shots, catalog imagery, merch concepts.78- ui-mockup — app/web interface mockups that look shippable.79- infographic-diagram — diagrams/infographics with structured layout and text.80- logo-brand — logo/mark exploration, vector-friendly.81- illustration-story — comics, children’s book art, narrative scenes.82- stylized-concept — style-driven concept art, 3D/stylized renders.83- historical-scene — period-accurate/world-knowledge scenes.8485Edit:86- text-localization — translate/replace in-image text, preserve layout.87- identity-preserve — try-on, person-in-scene; lock face/body/pose.88- precise-object-edit — remove/replace a specific element (incl. interior swaps).89- lighting-weather — time-of-day/season/atmosphere changes only.90- background-extraction — transparent background / clean cutout.91- style-transfer — apply reference style while changing subject/scene.92- compositing — multi-image insert/merge with matched lighting/perspective.93- sketch-to-render — drawing/line art to photoreal render.9495Quick clarification (augmentation vs invention):96- If the user says “a hero image for a landing page”, you may add *layout/composition constraints* that are implied by that use (e.g., “generous negative space on the right for headline text”).97- Do not introduce new creative elements the user didn’t ask for (e.g., adding a mascot, changing the subject, inventing brand names/logos).9899Template (include only relevant lines):100```101Use case: <taxonomy slug>102Asset type: <where the asset will be used>103Primary request: <user's main prompt>104Scene/background: <environment>105Subject: <main subject>106Style/medium: <photo/illustration/3D/etc>107Composition/framing: <wide/close/top-down; placement>108Lighting/mood: <lighting + mood>109Color palette: <palette notes>110Materials/textures: <surface details>111Quality: <low/medium/high/auto>112Input fidelity (edits): <low/high>113Text (verbatim): "<exact text>"114Constraints: <must keep/must avoid>115Avoid: <negative constraints>116```117118Augmentation rules:119- Keep it short; add only details the user already implied or provided elsewhere.120- Always classify the request into a taxonomy slug above and tailor constraints/composition/quality to that bucket. Use the slug to find the matching example in `references/sample-prompts.md`.121- If the user gives a broad request (e.g., "Generate images for this website"), use judgment to propose tasteful, context-appropriate assets and map each to a taxonomy slug.122- For edits, explicitly list invariants ("change only X; keep Y unchanged").123- If any critical detail is missing and blocks success, ask a question; otherwise proceed.124125## Examples126127### Generation example (hero image)128```129Use case: stylized-concept130Asset type: landing page hero131Primary request: a minimal hero image of a ceramic coffee mug132Style/medium: clean product photography133Composition/framing: centered product, generous negative space on the right134Lighting/mood: soft studio lighting135Constraints: no logos, no text, no watermark136```137138### Edit example (invariants)139```140Use case: precise-object-edit141Asset type: product photo background replacement142Primary request: replace the background with a warm sunset gradient143Constraints: change only the background; keep the product and its edges unchanged; no text; no watermark144```145146## Prompting best practices (short list)147- Structure prompt as scene -> subject -> details -> constraints.148- Include intended use (ad, UI mock, infographic) to set the mode and polish level.149- Use camera/composition language for photorealism.150- Quote exact text and specify typography + placement.151- For tricky words, spell them letter-by-letter and require verbatim rendering.152- For multi-image inputs, reference images by index and describe how to combine them.153- For edits, repeat invariants every iteration to reduce drift.154- Iterate with single-change follow-ups.155- For latency-sensitive runs, start with quality=low; use quality=high for text-heavy or detail-critical outputs.156- For strict edits (identity/layout lock), consider input_fidelity=high.157- If results feel “tacky”, add a brief “Avoid:” line (stock-photo vibe; cheesy lens flare; oversaturated neon; harsh bloom; oversharpening; clutter) and specify restraint (“editorial”, “premium”, “subtle”).158159More principles: `references/prompting.md`. Copy/paste specs: `references/sample-prompts.md`.160161## Guidance by asset type162Asset-type templates (website assets, game assets, wireframes, logo) are consolidated in `references/sample-prompts.md`.163164## CLI + environment notes165- CLI commands + examples: `references/cli.md`166- API parameter quick reference: `references/image-api.md`167- If network approvals / sandbox settings are getting in the way: `references/codex-network.md`168169## Reference map170- **`references/cli.md`**: how to *run* image generation/edits/batches via `scripts/image_gen.py` (commands, flags, recipes).171- **`references/image-api.md`**: what knobs exist at the API level (parameters, sizes, quality, background, edit-only fields).172- **`references/prompting.md`**: prompting principles (structure, constraints/invariants, iteration patterns).173- **`references/sample-prompts.md`**: copy/paste prompt recipes (generate + edit workflows; examples only).174- **`references/codex-network.md`**: environment/sandbox/network-approval troubleshooting.175
Full transparency — inspect the skill content before installing.