Home / All Skills / Content & Media Creation / canghe-image-gen
Content & Media Creation · freestylefly/canghe-skills

canghe-image-gen

AI image generation with OpenAI, Google, DashScope and Canghe APIs. Supports text-to-image, reference images, aspect ratios. Sequential by default; parallel generation available on request. Use when user asks to generate, create, or draw images.

L4 High-Privilege · Graded auth & full auditV1 Commit-PinnedExecute CommandNetwork AccessWrite FileDual-pass Audit
Author freestyleflyGitHub freestylefly/canghe-skills ↗License MIT(仓库根 LICENSE)Commit dd0bf35595
Control levels describe skill capabilities and suggested control measures; they do not represent quality or safety certifications, nor do they dictate usability. Usage decisions rest entirely with users and administrators. Different agent hosts apply varying constraints; do not assume hosts provide automatic protection. Third-party skill copyrights belong to their original authors. Use at your own risk.

1How It Works & Mechanism

The execution entity of this skill is a Bun/TypeScript CLI (scripts/main.ts), launched by the agent using npx -y bun according to SKILL.md; argument parsing, configuration merging, provider selection, and result saving are all completed at this entry point.

skills/canghe-image-gen/SKILL.md
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "A cat" --image cat.png
What is happening here: SKILL.md only provides the invocation method, while the actual entry point is the script; the script path is constructed using ${SKILL_DIR}.

Automatic provider selection: Explicit --provider takes priority; when --ref is provided, the order is Google -> OpenAI -> Canghe; without --ref, it picks the first available key found in the environment (Google takes precedence if multiple keys exist).

skills/canghe-image-gen/scripts/main.ts
const hasGoogle = !!(process.env.GOOGLE_API_KEY || process.env.GEMINI_API_KEY);
What is happening here: detectProvider infers the backend based on the presence of each API key; if keys are missing, it throws an error and prompts to create a .env file.

The four backends are modularized individually and unify under the ProviderModule interface (getDefaultModel / generateImage), each with different protocols: OpenAI uses images/generations and edits, Google uses Gemini generateContent or Imagen predict, DashScope uses the Tongyi Wanxiang endpoint, and Canghe uses OpenAI-compatible chat/completions.

skills/canghe-image-gen/scripts/providers/canghe.ts
const res = await fetch(`${getBaseUrl()}/chat/completions`, {
What is happening here: The Canghe gateway returns images as chat replies, and the script then extracts base64 data from the text using regular expressions.

Reference image support varies by backend: Google multimodal reads reference images as base64 into inlineData, OpenAI uses the /images/edits form, and Canghe transmits via image_url (local files are converted to data URIs, while http URLs are passed directly); DashScope and Imagen explicitly throw errors as unsupported.

skills/canghe-image-gen/scripts/providers/google.ts
const { data, mimeType } = await readImageAsBase64(refPath);
What is happening here: Gemini multimodal encodes local reference images and submits them alongside the prompt.

The configuration hierarchy priority is fixed as CLI args > EXTEND.md > environment variables > cwd/.canghe-skills/.env > ~/.canghe-skills/.env; main.ts parses the YAML front matter of EXTEND.md and .env key-value pairs on its own without relying on dotenv.

skills/canghe-image-gen/SKILL.md
**Load Priority**: CLI args > EXTEND.md > env vars > `<cwd>/.canghe-skills/.env` > `~/.canghe-skills/.env`
What is happening here: loadEnv and loadExtendConfig inject configurations into process.env according to this order.

Generation results are written in binary to the user-specified --image path (automatically appending .png if no extension is present), with directories created recursively prior to writing; failed generations are automatically retried only once, and errors such as 'reference image unsupported/missing key' are not retried.

skills/canghe-image-gen/scripts/main.ts
await writeFile(outputPath, imageData);
What is happening here: main() persists the image to disk after receiving the Uint8Array returned by the provider, and prints additional metadata when --json is specified.

Batch and parallel operations are two distinct modes: images are generated sequentially one by one by default; parallel generation is only enabled when explicitly requested by the user, running via the host's multiple background sub-agents (recommended 4, max 8); the script itself contains no parallel logic.

skills/canghe-image-gen/SKILL.md
**Parallel Generation**: Only use when user explicitly requests parallel/concurrent generation.
What is happening here: Parallel execution is an agent orchestration layer strategy and is not implemented inside main.ts.

2Core Capabilities

01Text-to-image: choice of four backends (OpenAI / Google / DashScope Tongyi Wanxiang / Canghe gateway) or automatic selection
02Reference image / image-to-image (Google multimodal, OpenAI GPT Image edits, Canghe image_url)
03Aspect ratio and dimension control (1:1, 16:9, 9:16, 4:3, 3:4, 2.35:1, and --size WxH)
04Quality/resolution presets: normal|2k, with Google also supporting --imageSize 1K|2K|4K
05Diverse prompt sources: inline text, multi-file concatenation via --promptfiles, stdin
06Preference persistence: default provider/quality/aspect ratio/size/model can be configured in EXTEND.md
07Batch count --n and JSON output --json (convenient for script/pipeline consumption)
08Explicit parallel generation (host multiple sub-agents, only upon user request)

3External Dependencies

KindDependency / Endpoint
clibun(经 npx -y bun 运行 TS 入口,会联网获取包)
apiOpenAI Images API
apiGoogle Generative Language API(Gemini / Imagen)
apiDashScope(阿里通义万象)
apiCanghe 第三方网关
packageNode 内建模块 node:fs/promises、node:path、node:os(经 Bun 运行)

4Recommended Governance & Evidence

Suggested Controls for Safe Operation
For Agent Runtime
Graded/per-use authorization, sandbox recommended
For Administrators
Approval workflow, rollback support, full audit
Evidence & Triggers (File Paths & Excerpts)
  • scripts/: Local script or command execution: npx -y bun ${SKILL_DIR}/scripts/main.ts (the sole CLI entry point executed by the agent according to SKILL.md)
  • 网络端点: Declared external network access: POST https://api.openai.com/v1/images/generations (openai.ts)
  • 本地工作目录: File read/write and artifact output: Image files at user-specified --image path (auto-appends .png if missing; main.ts runs mkdir -p before writeFile)
Audit Notes: Orange: Reads four API keys (environment variables and .env files) for its declared purpose, and sends user prompts and reference images to external OpenAI/Google/DashScope/Canghe generation backends, matching the Orange tier ('credential reading + material egress'). The script uses native Node/Bun fetch (verifying certificates by default), with no evidence of disabling TLS, reverse engineering/spoofing/bypassing protections, or arbitrary code execution, so it is not escalated to Red; since it involves local script execution, an external CLI (npx/bun fetching remote packages), and local disk writes, it is not downgraded to Blue.

5Second-Pass Verification

  • [ok] 执行入口是否唯一且真实存在 — SKILL.md 的调用示例与 main.ts 的 printUsage 一致(npx -y bun scripts/main.ts --prompt ... --image ...),main.ts 末尾 main().catch 会 process.exit(1),证明它是 CLI;目录仅 8 个档(SKILL.md + preferences-schema.md + main.ts + 4 个 provider + types.ts),无其它可执行文件。
  • [ok] 四家 provider 端点与凭证读取点 — openai.ts→api.openai.com/v1 + OPENAI_API_KEY;google.ts→generativelanguage.googleapis.com + GOOGLE_API_KEY/GEMINI_API_KEY;dashscope.ts→dashscope.aliyuncs.com + DASHSCOPE_API_KEY;canghe.ts→api.canghe.ai/v1 + CANGHE_API_KEY。均可用对应 *_BASE_URL 覆盖。
  • [ok] 是否漏掉网络外发 — 全目录除 providers/*.ts 的 fetch 外无网络能力:main.ts 只做 IO 与编排,types.ts / preferences-schema.md 无网络代码;未见 socket/child_process/exec/urllib。
  • [ok] TLS 是否被降级 — 四家后端都用 Node/Bun 原生 fetch(默认校验证书),未见 ssl.CERT_NONE / rejectUnauthorized=false / --no-verify,因此不触发红档。
  • [discrepancy] 「并行生成」宣称是否有代码支撑 — SKILL.md 的 Parallel Generation 段描述用宿主 Task 子代理 run_in_background=true 并发并给并发建议,但 scripts/main.ts 只有单次 --n 的串行生成,未实现任何并发;该能力完全依赖 agent 编排层,脚本不提供。
  • [ok] 默认 provider 与质量口径 — SKILL.md 写 default provider google、quality 2k;detectProvider 多 key 时返回 available[0](google 排第一),main.ts 对空 quality 置 '2k',与文档一致。
  • [ok] 参考图 provider 限制 — SKILL.md 称 --ref 受 Google 多模态 / OpenAI edits / Canghe 支持;google.ts 对 Imagen、openai.ts 对 dall-e、main.ts 对 dashscope+ref 均抛错,与文档相符。

6Verdict & Scenarios

  • A single script manages four image backends and routes automatically based on available keys; extending to a new provider requires only adding one file and implementing the unified interface, offering a clean design.
  • Hierarchical configuration with custom parsing of .env/EXTEND.md allows running with zero configuration; thoughtful engineering details (auto-appending .png, mkdir -p, retry allowlist).
  • Practical option coverage: aspect ratios, quality, reference images, prompt files, batching, and JSON output, making it ideal for invocation as a tool by other skills/scripts.
  • Best for: Creators and automated pipelines requiring scripted, batch, or multi-backend image generation; especially suited for scenarios embedding image generation capabilities into other agent workflows.
    Not for: Scenarios highly sensitive to data egress, requiring completely offline execution or zero data leaving the internal network; and users who only wish to use a single fixed backend without maintaining multiple keys.
    Install Agent-Ready
    ① Verified Mirror 2026-10-10
    Option A · Direct DownloadDownload canghe-image-gen.tar.gz
    sha256: 6d47e36b6c02f891…
    Option B · Copy Guide for Agent
    install.json
    Agents automatically download and verify mirrors from this JSON guide.
    ② Upstream GitHub
    GitHub Repo ↗
    Pinned to commit dd0bf35595.