Imagegen

From lightspeedwp/.github · View interactive version

Imagegen is an AI agent skill from the GitHub repository lightspeedwp/.github. Generate or edit raster images when the task benefits from AI-created bitmap visuals such as photos, illustrations, textures, sprites, mockups, or transparent-background cutouts. Use when Codex should create a brand-new image, transform an existing image, or derive visual variants from references, a

How to use this skill

Skill file

Image Generation Skill

Generates or edits images for the current project (for example website assets, game assets, UI mockups, product mockups, wireframes, logo design, photorealistic images, or infographics).

Top-level modes and rules

This skill has exactly two top-level modes:

Within CLI fallback, the CLI exposes three subcommands:

Rules:

Built-in save-path policy:

1. If the user names a destination, move or copy the selected output there.

2. If the image is meant for the current project, move or copy the final selected image into the workspace before finishing.

3. If the image is only for preview or brainstorming, render it inline; the underlying file can remain at the default $CODEX_HOME/* path.

Shared prompt guidance for both modes lives in references/prompting.md and references/sample-prompts.md.

Fallback-only docs/resources for CLI mode:

Local post-processing helper:

When to use

When not to use

Decision tree

Think about two separate questions:

  1. Intent: is this a new image or an edit of an existing image?
  2. Execution strategy: is this one asset or many assets/variants?

Intent:

Built-in edit semantics:

Execution strategy:

Assume the user wants a new image unless they clearly ask to change an existing one.

Workflow

  1. Decide the top-level mode: built-in by default, including simple transparent-output requests; fallback CLI only if explicitly requested or after the user explicitly confirms a transparent-output fallback.
  2. Decide the intent: generate or edit.
  3. Decide whether the output is preview-only or meant to be consumed by the current project.
  4. Decide the execution strategy: single asset vs repeated built-in calls vs CLI generate-batch.
  5. Collect inputs up front: prompt(s), exact text (verbatim), constraints/avoid list, and any input images.
  6. For every input image, label its role explicitly:
  1. If the edit target is only on the local filesystem and you are staying on the built-in path, inspect it with view_image first so the image is available in conversation context.
  2. If the user asked for a photo, illustration, sprite, product image, banner, or other explicitly raster-style asset, use image_gen rather than substituting SVG/HTML/CSS placeholders. If the request is for an icon, logo, or UI graphic that should match existing repo-native SVG/vector/code assets, prefer editing those directly instead.
  3. Augment the prompt based on specificity:
  1. Use the built-in image_gen tool by default.
  2. For transparent-output requests, follow the transparent image guidance below: generate with built-in image_gen on a flat chroma-key background, copy the selected output into the workspace or tmp/imagegen/, run the installed $CODEX_HOME/skills/.system/imagegen/scripts/remove_chroma_key.py helper, and validate the alpha result before using it. If this path looks unsuitable or fails, ask before switching to CLI gpt-image-1.5.
  3. Inspect outputs and validate: subject, style, composition, text accuracy, and invariants/avoid items.
  4. Iterate with a single targeted change, then re-check.
  5. For preview-only work, render the image inline; the underlying file may remain at the default $CODEX_HOME/generated_images/... path.
  6. For project-bound work, move or copy the selected artifact into the workspace and update any consuming code or references. Never leave a project-referenced asset only at the default $CODEX_HOME/generated_images/... path.
  7. For batches or multi-asset requests, persist every requested deliverable final in the workspace unless the user explicitly asked to keep outputs preview-only. Discarded variants do not need to be kept unless requested.
  8. If the user explicitly chooses or confirms the CLI fallback, then use the fallback-only docs for model, quality, size, input_fidelity, masks, output format, output paths, and network setup.
  9. Always report the final saved path(s) for any workspace-bound asset(s), plus the final prompt or prompt set and whether the built-in tool or fallback CLI mode was used.

Transparent image requests

Transparent-image requests still use built-in image_gen first. Because the built-in tool does not expose a true transparent-background control, create a removable chroma-key source image and then convert the key color to alpha locally.

Default sequence:

  1. Use built-in image_gen to generate the requested subject on a perfectly flat solid chroma-key background.
  2. Choose a key color that is unlikely to appear in the subject: default #00ff00, use #ff00ff for green subjects, and avoid #0000ff for blue subjects.
  3. After generation, move or copy the selected source image from $CODEX_HOME/generated_images/... into the workspace or tmp/imagegen/.
  4. Run the installed helper path, not a project-relative script path:

```bash

python "${CODEX_HOME:-$HOME/.codex}/skills/.system/imagegen/scripts/remove_chroma_key.py" \

--input <source> \

--out <final.png> \

--auto-key border \

--soft-matte \

--transparent-threshold 12 \

--opaque-threshold 220 \

--despill

```

  1. Validate that the output has an alpha channel, transparent corners, plausible subject coverage, and no obvious key-color fringe. If a thin fringe remains, retry once with --edge-contract 1; use --edge-feather 0.25 only when the edge is visibly stair-stepped and the subject is not shiny or reflective.
  2. Save the final alpha PNG/WebP in the project if the asset is project-bound. Never leave a project-referenced transparent asset only under $CODEX_HOME/*.

Prompt transparent requests like this:

Create the requested subject on a perfectly flat solid #00ff00 chroma-key background for background removal.
The background must be one uniform color with no shadows, gradients, texture, reflections, floor plane, or lighting variation.
Keep the subject fully separated from the background with crisp edges and generous padding.
Do not use #00ff00 anywhere in the subject.
No cast shadow, no contact shadow, no reflection, no watermark, and no text unless explicitly requested.

Do not automatically use CLI gpt-image-1.5 --background transparent --output-format png instead of chroma keying. Ask the user first when the user asks for true/native transparency, when local removal fails validation, or when the requested image is complex: hair, fur, feathers, smoke, glass, liquids, translucent materials, reflective objects, soft shadows, realistic product grounding, or subject colors that conflict with all practical key colors.

Use a concise confirmation like:

This likely needs true native transparency. The default built-in path uses a chroma-key background plus local removal, but true transparency requires the CLI fallback with gpt-image-1.5 because gpt-image-2 does not support background=transparent. It also requires OPENAI_API_KEY. Should I proceed with that CLI fallback?

Prompt augmentation

Reformat user prompts into a structured, production-oriented spec. Make the user's goal clearer and more actionable, but do not blindly add detail.

Treat this as prompt-shaping guidance, not a closed schema. Use only the lines that help, and add a short extra labeled line when it materially improves clarity.

Specificity policy

Use the user's prompt specificity to decide how much augmentation is appropriate:

Allowed augmentations:

Not allowed augmentations:

Use-case taxonomy (exact slugs)

Classify each request into one of these buckets and keep the slug consistent across prompts and references.

Generate:

Edit:

Shared prompt schema

Use the following labeled spec as shared prompt scaffolding for both top-level modes:

Use case: <taxonomy slug>
Asset type: <where the asset will be used>
Primary request: <user's main prompt>
Input images: <Image 1: role; Image 2: role> (optional)
Scene/backdrop: <environment>
Subject: <main subject>
Style/medium: <photo/illustration/3D/etc>
Composition/framing: <wide/close/top-down; placement>
Lighting/mood: <lighting + mood>
Color palette: <palette notes>
Materials/textures: <surface details>
Text (verbatim): "<exact text>"
Constraints: <must keep/must avoid>
Avoid: <negative constraints>

Notes:

Augmentation rules:

Examples

Generation example (hero image)

Use case: product-mockup
Asset type: landing page hero
Primary request: a minimal hero image of a ceramic coffee mug
Style/medium: clean product photography
Composition/framing: wide composition with usable negative space for page copy if needed
Lighting/mood: soft studio lighting
Constraints: no logos, no text, no watermark

Edit example (invariants)

Use case: precise-object-edit
Asset type: product photo background replacement
Primary request: replace only the background with a warm sunset gradient
Constraints: change only the background; keep the product and its edges unchanged; no text; no watermark

Prompting best practices

More principles shared by both modes: references/prompting.md.

Copy/paste specs shared by both modes: references/sample-prompts.md.

Guidance by asset type

Asset-type templates (website assets, game assets, wireframes, logo) are consolidated in references/sample-prompts.md.

gpt-image-2 guidance for CLI fallback

The fallback CLI defaults to gpt-image-2.

Popular gpt-image-2 sizes:

Fallback CLI mode only

Temp and output conventions

These conventions apply only to the CLI fallback. They do not describe built-in image_gen output behavior.

Dependencies

Prefer uv for dependency management in this repo.

Required Python package:

uv pip install openai

Required for local chroma-key removal and optional downscaling:

uv pip install pillow

Portability note:

Environment

If the key is missing, give the user these steps:

  1. Create an API key in the OpenAI platform UI: <https://platform.openai.com/api-keys>
  2. Set OPENAI_API_KEY as an environment variable in their system.
  3. Offer to guide them through setting the environment variable for their OS/shell if needed.

If installation is not possible in this environment, tell the user which dependency is missing and how to install it into their active environment.

Script-mode notes

Reference map

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.