CommunityImagegithub.com

local-image-generation

Generate and edit images with a local or remote ComfyUI / Stable Diffusion server. Point it at any server address, discover models and VRAM, run txt2img, img2img, inpaint and upscale, download and verify model files, and recover from VRAM/OOM problems. Use for ComfyUI, SDXL, Illustrious, NoobAI, Anima, LoRA, Stable Diffusion, model downloads, and offline image workflows.

What is local-image-generation?

local-image-generation is a Codex agent skill that generate and edit images with a local or remote ComfyUI / Stable Diffusion server. Point it at any server address, discover models and VRAM, run txt2img, img2img, inpaint and upscale, download and verify model files, and recover from VRAM/OOM problems. Use for ComfyUI, SDXL, Illustrious, NoobAI, Anima, LoRA, Stable Diffusion, model downloads, and offline image workflows.

Works with~Claude Code✓Codex CLI~Cursor
npx skills add https://github.com/bravegentleman/local-image-generation/tree/HEAD

Installed? Explore more Image skills: steipete/songsee, affaan-m/frontend-design, mattpocock/improve-codebase-architecture · View all 6 →

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

Local image generation with ComfyUI

This skill is a portable operating manual plus a small CLI. It talks to ComfyUI over HTTP, so it works with a local install or a remote server, on Windows, macOS or Linux, from any agent that can run Python.

Do not assume the port, the model name, the install path, or that the GPU is free. Measure first; every command below reports what it actually found.

Before running commands

  • Examples assume the current directory is this skill's directory. If your runtime loads the skill from elsewhere, cd there first, or use the absolute path: python /path/to/local-image-generation/scripts/comfy.py ....
  • Keep --out inside the user's workspace, not inside the skill directory.
  • python means python3 on systems that only provide that name.
  • Examples are single-line so they paste into bash, zsh, PowerShell, and cmd. If a prompt contains quotes or non-ASCII text that the shell mangles, write it to a UTF-8 file and use --prompt-file prompt.txt.
  • Every script supports --help; use it instead of guessing an option name.

Point at the right server (once per machine)

If ComfyUI is local on a default port, doctor finds it automatically — do not ask the user for an address in that case. Ask only when discovery fails or picks the wrong instance: ComfyUI may be on another computer, a different port, or behind a proxy. Then save the address:

python scripts/comfy.py connect http://192.168.1.20:8188

connect checks GET /system_stats, then stores the address. Every later command (doctor, models, txt2img, ...) uses it automatically, so an agent never needs to repeat --url.

  • One-off override: --url http://host:8188 (accepted before or after the subcommand) or COMFY_URL in the environment.
  • Inspect: python scripts/comfy.py config
  • Forget: python scripts/comfy.py disconnect
  • The config lives at %APPDATA%\local-image-generation\config.json on Windows and ~/.config/local-image-generation/config.json elsewhere (override with COMFY_CONFIG).

Precedence: --url > COMFY_URL > saved config > localhost port scan. An explicitly configured server is authoritative: if it is unreachable the command fails with the address in the message instead of silently using another instance.

0. Discover the server

python scripts/comfy.py doctor

It prints the URL, where that URL came from (source=config/env/flag), ComfyUI version, GPU/VRAM, RAM, the installation directory when it can infer it, installed models, and capabilities. Add --json to parse it. If it fails, ask the user for the address and run connect; then read references/discovery.md. If ComfyUI is not installed anywhere, read references/setup.md.

Rules:

  • A directory named "ComfyUI" is not proof of anything. Trust the HTTP API and the live process, not folder names.
  • Models must be installed in the directories of the running instance (<install>/ComfyUI/models/..., or <install>/models/... for a git checkout). doctor reports comfy_dir when it can prove it.
  • Set the address with connect, or override per command with --url / COMFY_URL, when discovery picks the wrong instance. Set COMFYUI_DIR when comfy_dir is unknown but you need restart or manual model placement.

1. Choose a model and know its family

python scripts/comfy.py models
  • All-in-one checkpoint (SDXL/SD1.5 finetunes): loaded with CheckpointLoaderSimple; VAE and CLIP are inside the file.
  • Separated model (e.g. Anima): needs diffusion_models/ + a text encoder
    • a VAE, loaded with UNETLoader + CLIPLoader + VAELoader. A file dropped into checkpoints/ will not appear as a usable checkpoint.
  • For anime, SDXL finetunes (Illustrious, NoobAI, Animagine) are the safe default. Official SD3/SD3.5 weights follow long natural-language captions and obey danbooru tags weakly.
  • LoRA compatibility is decided by metadata, not by filename:
python scripts/safetensors_info.py path/to/lora.safetensors

Check architecture (e.g. anima-preview/lora) and ss_network_module. A model-only LoRA (no text-encoder tensors) must use LoraLoaderModelOnly; the CLI does that automatically for separated models. Do not mix SDXL LoRAs with a different architecture.

comfy.py infers sensible defaults per family (resolution, steps, CFG, sampler/scheduler). Override any of them explicitly when the model card says otherwise. Details and the family table: references/models.md.

2. Generate

python scripts/comfy.py txt2img --model Illustrious-XL-v1.1.safetensors --prompt "1girl, full body, white background, looking at viewer" --negative "low quality, worst quality, bad anatomy, bad hands, watermark" --width 896 --height 1344 --seeds 1,2,3 --out ./gen
  • --seeds a,b,c produces one job per seed; --batch N produces N images per job. Keep the seed fixed when comparing anything else. A single seed (--seeds 1) is fine for a quick check; use 4–6 for selection.
  • --width/--height accept any multiple of 8. For SDXL, staying near 1 MP gives noticeably better anatomy than 512×512, which is below its training resolution; use small sizes only for fast tests.
  • Outputs are downloaded to --out and the saved paths are printed (or returned as JSON with --json).
  • Start with 4–6 seeds, inspect, then refine. Do not claim success without looking at the result or running a QC check (step 3).
  • Prompt craft, negative prompts, weights, resolution ranges and LoRA strength guidance: references/generation.md.

3. Inspect, QC, iterate

If you can view images (attach or open the saved file), do that first — it is faster and more reliable than any proxy metric.

If you cannot see images, choose one:

# A vision endpoint (OpenAI-compatible) scores and sorts a batch
python scripts/qc_image.py "gen/*.png" --base https://api.openai.com/v1 --model gpt-4o-mini

# Pixel-level checks that need no model
python scripts/image_tools.py info gen/a.png      # size, mode, mean color
python scripts/image_tools.py colors gen/a.png
python scripts/image_tools.py diff before.png after.png
python scripts/image_tools.py sheet sheet.png gen/*.png --cols 2 --labels

QC is a relative ranking tool, not an oracle. Ask countable, checkable questions ("how many fingers on each hand", "is the left hand actually gripping the handle"), crop the region in question, and normalize scores that come back on a 100-point scale. More in references/qc.md.

Iterate by changing one variable at a time:

# img2img: denoise ladder; 0.30 recolors, 0.45 starts redrawing, 0.55 distorts
python scripts/comfy.py img2img --image gen/base.png --denoise 0.35 --prompt "same character, pale skin" --out ./gen

# inpaint: white mask = repaint; protects everything else
python scripts/image_tools.py mask gen/base.png hand_mask.png --rel 0.28,0.64,0.70,0.86 --feather 8
python scripts/comfy.py inpaint --image gen/base.png --mask hand_mask.png --prompt "five clearly separated fingers, gripping the handle" --denoise 1.0 --out ./gen

# upscale: adds resolution without redrawing anatomy
python scripts/comfy.py upscale --image gen/final.png --model 4x-AnimeSharp.pth --out ./gen

For editing strategy, denoise sweet spots, skin-tone fixes, color fidelity and the limits of each method, read references/editing.md.

4. VRAM and OOM recovery

Check doctor for vram_free. If generation fails with OOM:

python scripts/comfy.py free          # unload cached models, keeps the process
python scripts/comfy.py restart --dry-run   # inspect the relaunch command
python scripts/comfy.py restart --yes       # destructive: kills the port listener
  • A local LLM or another GPU app can silently reload itself after you kill it; verify free VRAM twice before generating.
  • After a real OOM, ComfyUI's CUDA allocator can stay poisoned: free will not help, only a process restart will. --dry-run first; ask the user before restarting a shared server.
  • Full symptom → cause → fix table: references/troubleshooting.md.

5. Download and install models

python scripts/seg_download.py "https://hf-mirror.com/<repo>/resolve/main/<file>" model.safetensors --parts 8 --sha256 <expected>
python scripts/safetensors_info.py model.safetensors
  • One connection is often throttled; several Range connections usually are not. Some mirrors (ModelScope) throttle concurrency instead — try --parts 1 there.
  • Always verify: byte size, safetensors header, and SHA-256 when the source publishes one. "The file exists" is not verification.
  • Put the file in the directory the running instance actually scans (models/checkpoints, models/diffusion_models, models/loras, ...), then re-run models and confirm ComfyUI lists it.
  • Ask before downloading multi-gigabyte files. Mirror behavior, layout rules and validation details: references/models.md.

6. Deliver

  • Copy final files to a stable, user-visible directory (not a temp/scratch dir).
  • Show the image itself when the interface supports it; a score alone is not a deliverable. Offer 2–4 candidates rather than one, and state model, seed and resolution.
  • Do not describe an image you have not inspected.

Reference map

FileRead when
references/setup.mdComfyUI is not installed, or you need ports / remote access / skill install paths
references/discovery.mddoctor fails, multiple instances, remote server, or mapping dirs to models
references/models.mdChoosing/downloading models, checkpoints vs separated, LoRA architecture, VRAM budgets
references/generation.mdPrompting, per-family parameters, resolutions, batching, LoRA strength
references/editing.mdimg2img, inpaint, skin/color edits, upscale, preserving identity
references/qc.mdSelf-checking without vision, scoring, pixel statistics, contact sheets
references/troubleshooting.mdOOM, queue stalls, node errors, missing models, download failures
references/api.mdNo shell available: raw HTTP endpoints and graph JSON

Guardrails

  • restart is destructive. Inspect with --dry-run and get user confirmation before killing a shared or remote server.
  • Uploading a user's image to a remote ComfyUI or a vision API is data sharing; ask first when it is private material.
  • A ComfyUI bound to 0.0.0.0 has no authentication; do not expose it to the internet without a proxy.
  • Respect model licenses and the user's local content rules; do not download weights the user did not ask for.

Related Skills