"imagegen"

Codex skill for AI image generation — supports built-in tool, custom endpoints (9Router, etc), auto-reads auth.json

afu-it
開発者 afu-it
メディア · JavaScript · 更新日: 6 months ago
0
スター
0
Forks
コミュニティ
BBB
安全性:
普通
BBB
品質:

name: "imagegen" description: "Use when the user asks to generate or edit images (e.g., generate image, edit/inpaint/mask, background removal, transparent background, product shots, concept art, covers, or batch variants). Runs built-in image_generation_call first, then falls back to custom endpoint via auth.json."

Image Generation Skill

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

When to use

Decision tree (generate vs edit vs batch)


Environment — Priority Order

1st choice: Built-in image_generation_call (PREFERRED)

If built-in tool is available in this session → use it directly.
Best quality, no API key needed, platform-handled.
Skip all steps below if this works.

2nd choice: Custom endpoint via auth.json

Only if built-in tool is NOT available in this session.

Read credentials from ~/.config/imagegen/auth.json:

{
  "endpoint": "https://your-proxy-or-api/v1/images/generations",
  "api_key": "YOUR_KEY_HERE",
  "model": "cx/gpt-5.4-image"
}

Auto-detect and run:

python3 - <<'PY'
import json, os, subprocess, sys
from pathlib import Path

auth_path = Path.home() / '.config' / 'imagegen' / 'auth.json'
if not auth_path.exists():
    sys.exit("[imagegen] auth.json not found. See SETUP.md for instructions.")

auth = json.loads(auth_path.read_text())
endpoint = auth.get('endpoint', '').strip()
api_key  = auth.get('api_key', '').strip()
model    = auth.get('model', 'gpt-image-1').strip()

if not endpoint or not api_key:
    sys.exit("[imagegen] auth.json is missing 'endpoint' or 'api_key'.")

print(f"[imagegen] Using endpoint: {endpoint}")
print(f"[imagegen] Model: {model}")
PY

Full curl call:

python3 scripts/image_gen.py generate \
  --prompt "<PROMPT>" \
  --model "$(python3 -c "import json,pathlib; d=json.loads(pathlib.Path.home().joinpath('.config/imagegen/auth.json').read_text()); print(d.get('model','gpt-image-1'))")"\
  --out output/imagegen/<filename>.png

OR via direct curl (SSE stream):

ENDPOINT=$(python3 -c "import json,pathlib; d=json.loads(pathlib.Path.home().joinpath('.config/imagegen/auth.json').read_text()); print(d['endpoint'])")
API_KEY=$(python3 -c "import json,pathlib; d=json.loads(pathlib.Path.home().joinpath('.config/imagegen/auth.json').read_text()); print(d['api_key'])")
MODEL=$(python3 -c "import json,pathlib; d=json.loads(pathlib.Path.home().joinpath('.config/imagegen/auth.json').read_text()); print(d.get('model','gpt-image-1'))")

curl -sS -N -X POST "$ENDPOINT" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Accept: text/event-stream" \
  -d "{\"model\":\"$MODEL\",\"prompt\":\"<PROMPT>\",\"n\":1,\"size\":\"auto\",\"quality\":\"high\",\"output_format\":\"png\"}" \
  -o tmp/imagegen/response.raw

# Parse SSE and save PNG
python3 - <<'PY'
import json, base64
from pathlib import Path

raw = Path('tmp/imagegen/response.raw').read_text(errors='replace')
final = None
for block in raw.strip().split('\n\n'):
    lines = block.splitlines()
    ev   = next((l[6:].strip() for l in lines if l.startswith('event:')), '')
    data = ''.join(l[5:].strip() for l in lines if l.startswith('data:'))
    if ev == 'done' and data:
        final = json.loads(data)

if not final:
    raise SystemExit('[imagegen] No done event in SSE response.')

out = Path('output/imagegen/result.png')
out.parent.mkdir(parents=True, exist_ok=True)
out.write_bytes(base64.b64decode(final['data'][0]['b64_json']))
print(f'[imagegen] Saved: {out} ({out.stat().st_size:,} bytes)')
PY

STOP conditions (strict)


Workflow

  1. Environment check (strict order):

    • a. Built-in image_generation_call tool available? → use it, proceed to step 1
    • b. ~/.config/imagegen/auth.json exists and valid? → use curl/SDK path, proceed
    • c. Neither available → STOP. Report: "Built-in tool unavailable and auth.json not found. See SETUP.md."
    • d. NEVER ask for or use a hardcoded API key
  2. Decide intent: generate vs edit vs batch (see decision tree above)

  3. Collect inputs: prompt(s), exact text (verbatim), constraints, and any input image(s)/mask(s)

  4. If batch: write temp JSONL under tmp/imagegen/, run once, delete JSONL after

  5. Augment prompt into a short labeled spec (structure + constraints)

  6. Run image generation via priority order above

  7. Inspect outputs and validate: subject, style, composition, text accuracy, constraints

  8. Iterate with single targeted change if needed

  9. Save final outputs to output/imagegen/ and note the final prompt used


Defaults & rules


Prompt augmentation

Reformat user prompts into a structured spec. Only make implicit details explicit; do not invent new requirements.

Template:

Use case: <taxonomy slug>
Asset type: <where the asset will be used>
Primary request: <user's main prompt>
Scene/background: <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>
Quality: <low/medium/high/auto>
Text (verbatim): "<exact text>"
Constraints: <must keep/must avoid>
Avoid: <negative constraints>

Use-case taxonomy

Generate: photorealistic-natural, product-mockup, ui-mockup, infographic-diagram, logo-brand, illustration-story, stylized-concept, historical-scene
Edit: text-localization, identity-preserve, precise-object-edit, lighting-weather, background-extraction, style-transfer, compositing, sketch-to-render


Reference map

🔓 サインインしてさらに解放
GitHub でサインイン