بنقرة واحدة
generate-image
使用 Gemini Nano Banana 2 產生圖片。當用戶說「產圖」「生成圖片」「generate image」「畫一張圖」時使用。
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
使用 Gemini Nano Banana 2 產生圖片。當用戶說「產圖」「生成圖片」「generate image」「畫一張圖」時使用。
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Generate self-contained HTML architecture diagrams (inline SVG, dark theme, no JS) for blogs/READMEs. Triggers on system architecture, microservices, cloud/AWS/GCP, K8s, network topology, data flow diagrams. Use `drawio` instead when the output needs to be editable.
Generate draw.io diagrams (.drawio files) with optional PNG/SVG/PDF export. Triggers on diagram/flowchart/ER/sequence/class/network/architecture/wireframe/mockup/UI sketch requests.
Resume/CV optimization. Analyze a resume, reposition strengths, and produce an optimized PDF tailored to a target role.
Virtual expert roundtable. Multiple thinkers analyze a document with different frameworks, then synthesize consensus/disagreements/blind spots.
Vendor proposal evaluation. Analyze technical architecture, pricing, and market benchmarks from a proposal PDF/Doc. Output evaluation report + comparison.
把 CSV/TSV 資料自動生成圖表(line/bar/pie/scatter)。當用戶說「畫圖表」「csv 圖表」「chart」「visualize data」時使用。
| name | generate-image |
| description | 使用 Gemini Nano Banana 2 產生圖片。當用戶說「產圖」「生成圖片」「generate image」「畫一張圖」時使用。 |
| argument-hint | [圖片描述 prompt,或留空進入互動模式] |
| allowed-tools | Bash(python3*), Bash(echo*), Read, Write |
| author | Maki |
| version | 1.0.0 |
| tags | ["image","gemini","ai"] |
| required_env | ["GEMINI_API_KEY"] |
透過 Google Gemini 最新圖像模型(Nano Banana 2)生成圖片,儲存到本機。
在做任何事之前,先確認用戶有 API Key。依序檢查:
python3 -c "
import os
key = os.environ.get('GEMINI_API_KEY') or os.environ.get('GOOGLE_API_KEY') or ''
if key:
print('KEY_FOUND')
else:
print('KEY_NOT_FOUND')
"
找不到 Gemini API Key。請提供你的 API Key:
1. 到 https://aistudio.google.com/apikey 申請(免費)
2. 然後用以下任一方式提供:
a) 直接貼給我(本次 session 有效)
b) 加到 shell 環境:export GEMINI_API_KEY="your-key-here"
c) 加到 .env 檔案:echo 'GEMINI_API_KEY=your-key-here' >> ~/.env
等用戶提供 key 後,用他給的值繼續。不要在沒有 key 的情況下嘗試呼叫 API。
根據 $ARGUMENTS 判斷:
將用戶描述優化為英文 prompt(Gemini 對英文 prompt 效果最好)。遵循原則:
Prompt 範例:
Clean modern tech blog illustration, 16:9 aspect ratio, minimalist style.
Visual metaphor for AI-powered knowledge management.
Cool blue and grey tones with warm orange accent colors.
Abstract geometric shapes representing data flow, no text, no human faces.
向用戶展示優化後的 prompt,確認後繼續。
python3 << 'PYEOF'
import json, os, sys, base64, urllib.request, urllib.error
# --- API Key ---
API_KEY = os.environ.get("GEMINI_API_KEY") or os.environ.get("GOOGLE_API_KEY") or "USER_PROVIDED_KEY_HERE"
# --- 設定 ---
PROMPT = """USER_PROMPT_HERE"""
OUTPUT_PATH = "/tmp/generated-image.png"
MODEL = "gemini-3.1-flash-image-preview" # Gemini 圖像生成(穩定版)
# --- 呼叫 Gemini API ---
url = f"https://generativelanguage.googleapis.com/v1beta/models/{MODEL}:generateContent?key={API_KEY}"
payload = {
"contents": [{
"parts": [{"text": PROMPT}]
}],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"]
}
}
req = urllib.request.Request(
url,
data=json.dumps(payload).encode("utf-8"),
headers={"Content-Type": "application/json"},
method="POST",
)
try:
with urllib.request.urlopen(req, timeout=120) as resp:
result = json.loads(resp.read().decode())
except urllib.error.HTTPError as e:
body = e.read().decode()
print(f"API Error {e.code}: {body}", file=sys.stderr)
sys.exit(1)
# --- 從回應中提取圖片 ---
saved = False
for candidate in result.get("candidates", []):
for part in candidate.get("content", {}).get("parts", []):
if "inlineData" in part:
img_data = base64.b64decode(part["inlineData"]["data"])
mime = part["inlineData"].get("mimeType", "image/png")
ext = {"image/png": ".png", "image/jpeg": ".jpg", "image/webp": ".webp"}.get(mime, ".png")
out = OUTPUT_PATH.rsplit(".", 1)[0] + ext
with open(out, "wb") as f:
f.write(img_data)
print(f"IMAGE_SAVED:{out} ({len(img_data)} bytes)")
saved = True
break
if saved:
break
if not saved:
# 印出回應以便 debug
print("No image in response. Full response:")
print(json.dumps(result, ensure_ascii=False, indent=2)[:2000])
sys.exit(1)
PYEOF
重要替換:
USER_PROVIDED_KEY_HERE → 用戶提供的 API Key(如果環境變數沒有的話)USER_PROMPT_HERE → Step 2 優化後的 promptOUTPUT_PATH → 依用途調整檔名圖片生成後:
圖片已生成!
檔案:/tmp/generated-image.png
大小:{size}
Prompt:{prompt}
滿意嗎?如果要調整,告訴我哪裡需要修改。
如果用戶指定了儲存位置:
cp /tmp/generated-image.png "{TARGET_PATH}"
| 模型 ID | 特性 |
|---|---|
gemini-3.1-flash-image-preview(預設) | 最新圖像生成,品質好 |
gemini-2.0-flash-preview-image-generation | 備用(舊版) |
模型 ID 可能隨 Google 更新而變動。如果遇到 404 錯誤,請查閱 https://ai.google.dev/gemini-api/docs/image-generation 確認最新模型 ID。