本文へ移動
cccskills
無料GitHub で公開

draw-image

Generate diagrams, flowcharts, and conceptual illustrations using OpenAI gpt-image-2 (default) or gpt-image-1. Use for: algorithm/code flow diagrams, system architecture sketches, conceptual illustrations, and any figure that does NOT represent actual code execution output (data plots, model results, etc. must still be generated by running Python code). Requires OPENAI_API_KEY and OpenAI organization verification when used from Claude Code / API path. OpenAI Codex subscribers can use built-in $imagegen without an API key.

インストール方法を見る

含まれるファイル(1)

  • SKILL.md9.6 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

draw-image: OpenAI gpt-image-2 图像生成


两种使用路径

路径工具是否需要 API Key费用
路径 A(本 skill 默认)Claude Code + draw_image.py✅ 需要 OPENAI_API_KEY按 token 计费(见费用表)
路径 BOpenAI Codex(含 ChatGPT Plus/Pro 订阅)❌ 不需要额外 API Key订阅内 usage limit 扣减

本 skill 属于路径 A,设计用于 Claude Code 和 AutoMCM-Pro agent。
若你使用 OpenAI Codex(桌面 app / CLI),见下方"在 Codex 中使用"章节。


前置条件(路径 A — Claude Code)

第一步:申请 OpenAI API Key

  1. 访问 platform.openai.com/api-keys(需科学上网)
  2. 注册/登录 OpenAI 账号(需邮箱 + 手机号验证)
  3. 点击 "Create new secret key" → 复制 sk-proj-...
    ⚠️ 关闭弹窗后无法再次查看,务必立即保存
  4. 去 Billing 充值(最低 $5,2025 年起无免费额度)

第二步:组织验证(GPT Image 系列必须)

访问 platform.openai.com/settings/organization/general
完成"Organization Verification",否则调用 GPT Image 模型会返回 403。

第三步:配置到环境

# 临时(当前终端有效)
export OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxxxxx

# 永久(写入 shell 配置)
echo 'export OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxxxxx' >> ~/.bashrc
source ~/.bashrc

# 验证
echo $OPENAI_API_KEY | head -c 15

⚠️ 切勿把 API Key 写入代码文件或 git commit,.env 已在 .gitignore 中排除。

第四步:安装依赖

pip install "openai>=1.0"
python -c "import openai; print(openai.__version__)"

在 OpenAI Codex 中使用(路径 B,无需 API Key)

OpenAI Codex(ChatGPT Plus $20/月 及以上订阅已包含)内置 gpt-image-2 支持,
不消耗 API 额度,用自然语言或 $imagegen 关键字直接触发:

# Codex CLI 中自然语言触发
Generate a technical flowchart showing the AutoMCM pipeline steps

# 显式触发(更可靠)
$imagegen Clean flowchart: 建模流程 from 读取题目 to 生成PDF, white background

订阅内 usage limit 耗尽后,设置 OPENAI_API_KEY 可自动切换到 API 计费:

export OPENAI_API_KEY=sk-proj-...   # Codex CLI 检测到此变量后切换为 API 定价

Agent 调用前置检查(必须执行)

在生成任何图像前,先运行 --check:

python scripts/draw_image.py --check
输出含义Agent 应该做什么
method=api_key available=TrueOPENAI_API_KEY 已设置✅ 直接调用 --prompt 生成
method=codex_oauth available=TrueCodex 已登录,但脚本不能直接用 OAuth⚡ 改用 Codex CLI:$imagegen <prompt>
method=none available=False(退出码 2)无任何认证⏭ 跳过图像生成;在 LaTeX 中留 \missingfigure{描述} 占位,继续流水线

退出码 2 = "跳过"信号,不是错误。流水线不应因此中断。

# 示例:优雅跳过
python scripts/draw_image.py --check || {
  if [ $? -eq 2 ]; then
    echo "[draw_image] 跳过 — 无认证,继续流水线"
  fi
}

适用范围决策树

需要一张图?
├─ 内容来自代码运行数值(散点图、折线图、热力图、拟合曲线…)
│   └─ ✗ 不用本 skill → 必须用 matplotlib/seaborn 生成
└─ 非数值内容(流程图、架构图、概念示意)
    ├─ 极简几何图(≤3个框) → tikz 即可
    └─ 复杂流程图 / 概念插图
        ├─ --check 返回 api_key → python scripts/draw_image.py --prompt ...
        ├─ --check 返回 codex_oauth → $imagegen ... (Codex CLI)
        └─ --check 退出码 2 → 跳过,\missingfigure{} 占位

模型说明

模型最大分辨率特点何时使用
gpt-image-2 (默认)3840×2160最新,文字渲染更准,支持灵活分辨率论文插图、高质量输出
gpt-image-1.51536×1024gpt-image-1 的改进版中等需求
gpt-image-11536×1024稳定,经过充分测试兼容性需求
gpt-image-1-mini1024×1024轻量快速,价格低草稿、快速迭代

参数说明

参数默认值有效值说明
--prompt—任意文字(最多 32,000 字符)图像描述
--output—.png / .jpg / .webp保存路径
--modelgpt-image-2见上表模型选择
--size1024x1024任意 WxH(gpt-image-2 规则见下)分辨率
--qualitymediumlow medium high auto质量
--output-format从文件扩展名推断png jpeg webp格式
--compression—0–100jpeg/webp 压缩率
--backgroundopaqueopaque auto ⚠️ transparent 不支持于 gpt-image-2背景
--moderationautoauto low内容审核强度

gpt-image-2 分辨率规则

  • 每条边必须是 16px 的倍数
  • 最大边 ≤ 3840px
  • 长短边比 ≤ 3:1
  • 总像素:655,360 – 8,294,400

常用预设:1024x1024、1536x1024、1024x1536、2048x2048、2048x1152、3840x2160


调用示例

基础(算法流程图)

python scripts/draw_image.py \
  --prompt "Clean technical flowchart on white background, Chinese labels.
Steps: (1) 读取赛题 → (2) 识别问题类型 → (3) 文献调研 → (4) 建立数学模型
→ (5) 编写求解代码 → (6) 运行验证脚本 → Decision: 全部通过?
→ Yes: 写入LaTeX / No: 修复代码 回到(5).
Style: professional diagram, blue/gray color scheme, sans-serif font,
clear arrows, minimal decoration." \
  --output "CUMCM_Workspace/latex/images/fig00_pipeline.png" \
  --size 1024x1536 \
  --quality high

系统架构图(横版)

python scripts/draw_image.py \
  --prompt "System architecture diagram on white background.
Left: User inputs problem PDF. Center: AutoMCM-Pro Agent with three modules:
[Problem Analysis] [Model & Verify] [LaTeX Writing]. Right: Output PDF paper.
Arrows show data flow. Style: clean tech diagram, English labels, gray boxes." \
  --output "CUMCM_Workspace/latex/images/fig_architecture.png" \
  --size 2048x1152 \
  --quality high

草稿快速预览(低成本)

python scripts/draw_image.py \
  --prompt "Simple flowchart: A → B → C → D" \
  --output "draft_check.png" \
  --model gpt-image-1-mini \
  --quality low

WebP 格式(更小体积)

python scripts/draw_image.py \
  --prompt "..." \
  --output "fig.webp" \
  --output-format webp \
  --compression 20 \
  --quality high

Prompt 工程指南

流程图 Prompt 模板

"Clean technical flowchart on white background. [中/英] labels.
Steps: (1) [step1] → (2) [step2] → ...
Decision nodes: [condition] → Yes: [action_yes] / No: [action_no]
Style: professional, minimal, blue/gray color scheme,
sans-serif font, clear directional arrows."

架构图 Prompt 模板

"System architecture diagram, white background.
Components: [component list with roles].
Connections: [arrows describing data/control flow].
Style: clean labeled boxes, professional tech diagram, no decorative elements."

概念插图 Prompt 模板

"Scientific illustration: [scenario].
Show [element1] as [visual], [element2] as [visual].
Style: technical/scientific, clean white background, labeled key elements,
suitable for academic paper, no heavy text."

LaTeX 集成

\begin{figure}[htbp]
  \centering
  \includegraphics[width=0.85\textwidth]{images/fig00_pipeline.png}
  \caption{建模流程图}
  \label{fig:pipeline}
\end{figure}

路径说明:images/ 相对于 CUMCM_Workspace/latex/,与 \graphicspath{{images/}} 配合使用。


费用参考(gpt-image-2,2026-04-21 定价)

分辨率lowmediumhigh
1024×1024~$0.006~$0.053~$0.211
1536×1024~$0.005~$0.041~$0.165
1024×1536~$0.005~$0.041~$0.165

以 token 计费:Image output $30/M tokens,text input $5/M tokens。


错误处理

错误信息原因解决方案
OPENAI_API_KEY not set未设置 keyexport OPENAI_API_KEY=sk-proj-...
openai package not installed缺少依赖pip install "openai>=1.0"
HTTP 403 / organization_verification未完成组织验证访问 platform.openai.com/settings/organization/general
content_policy_violationPrompt 触发审核简化描述,避免真实人物/商标
invalid_sizegpt-image-2 尺寸不合规确保每边是 16 倍数,比例 ≤3:1
API returned no image data响应无数据检查网络,重试

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

auto-mcm

無料

AutoMCM-Pro industrial-grade math modeling agent (opencode binding). Supports AP (AI-led) and Manual (human-spec-led) dual modes with mandatory GitOps checkpoints, forced self-verification of all solver code before LaTeX inclusion, and structured human cross-validation at each pipeline stage. Use for both CUMCM (Chinese) and MCM/ICM (English) competitions.

日本語の概要は準備中です。原文の説明を表示しています。

RealSeaberry/AutoMCM-Pro2582026年9月11日 更新

auto-mcm

無料

AutoMCM-Pro industrial-grade math modeling agent. Supports AP (AI-led) and Manual (human-spec-led) dual modes with mandatory GitOps checkpoints, forced self-verification of all solver code before LaTeX inclusion, and structured human cross-validation at each pipeline stage. Use for both CUMCM (Chinese) and MCM/ICM (English) competitions.

日本語の概要は準備中です。原文の説明を表示しています。

RealSeaberry/AutoMCM-Pro2582026年9月11日 更新

auto-mcm

無料

AutoMCM-Pro industrial-grade math modeling agent (Codex CLI binding). Supports AP (AI-led) and Manual (human-spec-led) dual modes with mandatory GitOps checkpoints, forced self-verification of all solver code before LaTeX inclusion, and structured human cross-validation at each pipeline stage. Use for both CUMCM (Chinese) and MCM/ICM (English) competitions.

日本語の概要は準備中です。原文の説明を表示しています。

RealSeaberry/AutoMCM-Pro2582026年9月11日 更新

auto-mcm

無料

AutoMCM-Pro industrial-grade math modeling agent (DeepSeek Harness binding). Supports AP (AI-led) and Manual (human-spec-led) dual modes with mandatory GitOps checkpoints, forced self-verification of all solver code before LaTeX inclusion, and structured human cross-validation at each pipeline stage. Use for both CUMCM (Chinese) and MCM/ICM (English) competitions.

日本語の概要は準備中です。原文の説明を表示しています。

RealSeaberry/AutoMCM-Pro2582026年9月11日 更新

Full-stack autonomous math modeling agent for CUMCM (全国大学生数学建模竞赛). Reads the problem statement and data, iterates through research → coding → verification → LaTeX writing, and produces a publication-quality PDF paper. Use when the user provides a CUMCM problem and wants end-to-end automated modeling, coding, and paper generation.

日本語の概要は準備中です。原文の説明を表示しています。

RealSeaberry/AutoMCM-Pro2582026年9月11日 更新

Full-stack autonomous math modeling agent for MCM/ICM (美国大学生数学建模竞赛). Handles team control number, problem choice (A–F), English academic writing, mcmthesis LaTeX template, and optional practical deliverable (memo/letter/report). Use when the user provides an MCM/ICM problem and wants end-to-end automated modeling, coding, and paper generation in English.

日本語の概要は準備中です。原文の説明を表示しています。

RealSeaberry/AutoMCM-Pro2582026年9月11日 更新

RealSeaberry のスキルをすべて見る

このスキルの問題を報告する