agentleFS
MakiDevelopMakiDevelop/claude-skills/skills/generate-image/SKILL.md

generate-image

Skill3 starsChanged 8 months agoMITView on GitHub

使用 Gemini Nano Banana 2 產生圖片。當用戶說「產圖」「生成圖片」「generate image」「畫一張圖」時使用。

  • Reads credentials

21 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use edit-image, generate-video and 4 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • SamurAIGPTSkill

    edit-image

    Edits an existing image using natural language instructions via MuAPI. Use when the user wants to modify, change, transform, or retouch an existing image.

    Also in 3 projects that use this

  • aslanzubairaevSkill

    generate-video

    Generate background videos using Veo 3 (Google Gemini) or Seedance 2 (PiAPI). Use when creating or regenerating video backgrounds for Reels slides.

    Also in 3 projects that use this

  • ZanderRussSkill

    scientific-slides

    Build slide decks and presentations for research talks. Use this for making PowerPoint slides, conference presentations, seminar talks, research presentations, thesis defense slides, or any scientific talk. Provides slide structure, design templates, timing guidance, and visual validation. Works with PowerPoint and LaTeX Beamer.

    Also in 3 projects that use this

  • AnthropicSkill

    pptx

    Use this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions \"deck,\" \"slides,\" \"presentation,\" or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill.

    Also in 4 projects that use this

  • AnthropicSkill

    xlsx

    Comprehensive spreadsheet creation, editing, and analysis with support for formulas, formatting, data analysis, and visualization. When Claude needs to work with spreadsheets (.xlsx, .xlsm, .csv, .tsv, etc) for: (1) Creating new spreadsheets with formulas and formatting, (2) Reading or analyzing data, (3) Modify existing spreadsheets while preserving formulas, (4) Data analysis and visualization in spreadsheets, or (5) Recalculating formulas

    Also in 3 projects that use this

  • +1 more from anthropics

The file

Files
SKILL.md

Gemini Nano Banana 2 圖片生成

目標

透過 Google Gemini 最新圖像模型(Nano Banana 2)生成圖片,儲存到本機。

流程

Step 0: 檢查 Gemini API Key

在做任何事之前,先確認用戶有 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')
"
  • 找到 → 繼續 Step 1
  • 沒找到 → 告訴用戶:
找不到 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。

Step 1: 確認圖片需求

根據 $ARGUMENTS 判斷:

  • 有 prompt → 直接使用
  • 空 → 詢問用戶想要什麼圖片,引導他描述:
    • 主題 / 場景
    • 風格(寫實、插畫、極簡、水彩...)
    • 色調偏好
    • 用途(blog feature image、social media、簡報...)

Step 2: 優化 Prompt

將用戶描述優化為英文 prompt(Gemini 對英文 prompt 效果最好)。遵循原則:

  • 具體描述構圖、光線、色調
  • 指定風格關鍵字(e.g., minimalist, watercolor, isometric, flat design)
  • 指定比例(16:9 for blog, 1:1 for social, 4:3 for presentation)
  • 避免過於抽象的描述

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,確認後繼續。

Step 3: 呼叫 Gemini API 生成圖片

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 優化後的 prompt
  • OUTPUT_PATH → 依用途調整檔名

Step 4: 展示結果

圖片生成後:

  1. 用 Read tool 讀取圖片檔案,展示給用戶看
  2. 告知檔案位置和大小
  3. 詢問是否滿意:
    • 滿意 → 詢問是否要搬到特定目錄
    • 不滿意 → 調整 prompt 重新生成(最多重試 2 次)
圖片已生成!

檔案:/tmp/generated-image.png
大小:{size}
Prompt:{prompt}

滿意嗎?如果要調整,告訴我哪裡需要修改。

Step 5: 儲存到目標位置(可選)

如果用戶指定了儲存位置:

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。

常見問題

API 回應沒有圖片

  • Gemini 有時會因為 safety filter 拒絕生成
  • 調整 prompt 避免敏感內容,重新嘗試

403 / 401 錯誤

  • API Key 無效或過期
  • 確認 Key 有啟用 Generative Language API

429 Too Many Requests

  • 免費額度用完,等一分鐘後重試
  • 或升級為付費方案

注意事項

  • Gemini 免費方案有每分鐘請求限制(通常 15 RPM)
  • 生成的圖片版權歸用戶所有(依 Google ToS)
  • 不要用來生成真人照片、有害內容、或侵權素材
  • API Key 不會被記錄或儲存到任何檔案中

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.