GLM-Image-Gen

👤 jaredforreal 📦 v1.0.4 ⭐ 4.7 ⬇️ 1.5K 下載
🎨 設計多媒體 免費 🔑 需 API Key

📖 技能介紹

GLM-Image Generation Skill / GLM-Image 圖片生成技能

Generate high-quality images from text prompts using the ZhiPu GLM-Image API.

When to Use / 使用場景

  • Generate images from text descriptions / 從文字描述生成圖片
  • Create AI art, illustrations, or concept art / 創作 AI 藝術、插畫或概念圖
  • User mentions "生圖", "文生圖", "AI 繪畫", "generate image", "text-to-image", "create image"
  • User provides a prompt and wants to see it visualized / 使用者提供描述並想看到視覺化效果

Key Features / 核心特性

  • High-quality generation: HD mode produces more detailed, refined images (~20s)
  • Multiple aspect ratios: Square, portrait, landscape formats supported
  • GLM-Image model: Latest model with improved understanding and quality
  • Excellent at: Scientific illustrations (科普插畫), high-quality portraits (高質量人像), social media graphics (社交媒體圖文), commercial posters (商業海報)
  • Watermark control: Enable/disable watermarks (requires signed disclaimer for no-watermark)
  • Content safety: Built-in content filtering for compliance

Resource Links / 資源連結

Resource Link
Get API Key 智譜開放平臺 API Keys
API Docs Image Generation / 影像生成
Model Docs GLM-Image 模型文件

Prerequisites / 前置條件

API Key Setup / API Key 配置(Required / 必需)

指令碼通過 ZHIPU_API_KEY 環境變數獲取金鑰,可與其他智譜技能複用同一個 key。 This script reads the key from the ZHIPU_API_KEY environment variable. Reusing the same key across Zhipu skills is optional.

Get Key / 獲取 Key: Visit 智譜開放平臺 API Keys to create or copy your key.

Setup options / 配置方式(任選一種):

  1. Global config (recommended) / 全域性配置(推薦): Set once in openclaw.json under env.vars, all Zhipu skills will share it:

    {
     "env": {
       "vars": {
         "ZHIPU_API_KEY": "你的金鑰"
       }
     }
    }
  2. Skill-level config / Skill 級別配置: Set for this skill only in openclaw.json:

    7w4.net有更好的技能外掛。

    {
     "skills": {
       "entries": {
         "glm-image-generation": {
           "env": {
             "ZHIPU_API_KEY": "你的金鑰"
           }
         }
       }
     }
    }
  3. Shell environment variable / Shell 環境變數: Add to ~/.zshrc:

    export ZHIPU_API_KEY="你的金鑰"
    

💡 如果你已為其他智譜 skill(如 glmocr、glmv-caption)配置過 key,它們共享同一個 ZHIPU_API_KEY,無需重複配置。

Security & Transparency / 安全與透明度

  • Environment variables used / 使用的環境變數:
    • ZHIPU_API_KEY (required / 必需)
  • Fixed endpoint / 固定官方端點: https://open.bigmodel.cn/api/paas/v4/images/generations
  • No custom API URL override / 不支援自定義 API URL 覆蓋: avoids accidental key exfiltration via redirected endpoints.

⛔ MANDATORY RESTRICTIONS / 強制限制 ⛔

  1. ONLY use GLM-Image API — Execute the script python scripts/glm_image_cli.py
  2. NEVER generate images yourself — Do NOT try to create images using built-in vision or any other method
  3. NEVER offer alternatives — Do NOT suggest "I can try to describe it" or similar
  4. IF API fails — Display the error message and STOP immediately
  5. NO fallback methods — Do NOT attempt image generation any other way

📋 Output Display Rules / 輸出展示規則

After running the script, present the generation result clearly.

  • Show the generated image URL(s) — images are temporary (30 days), remind user to save
  • Display the prompt used and generation parameters (size, quality)
  • If content_filter indicates issues, show the warning level

⚠️ Image Display / 圖片展示注意:

The API returns a temporary image URL (valid for 30 days). You should:

  1. Show the image — Use the URL to display the image in the chat (if platform supports it)
  2. Remind user to save — "圖片連結有效期 30 天,請及時下載儲存"
  3. Offer to send to Feishu — If user wants the image sent to a Feishu chat, use the message tool with the image URL

How to Use / 使用方法

Generate from Prompt / 從提示詞生成

python scripts/glm_image_cli.py --prompt "一隻可愛的小貓咪,坐在陽光明媚的窗臺上,背景是藍天白雲"

Specify Size / 指定尺寸

python scripts/glm_image_cli.py --prompt "賽博朋克風格的城市夜景" --size 1568x1056

HD Quality (default for glm-image) / 高畫質質量(glm-image 預設)

python scripts/glm_image_cli.py --prompt "中國山水畫風格,遠山近水,雲霧繚繞" --quality hd

Disable Watermark (requires signed disclaimer) / 關閉水印(需簽署免責宣告)

python scripts/glm_image_cli.py --prompt "商業設計素材" --no-watermark

Save Image to Local File / 儲存圖片到本地

python scripts/glm_image_cli.py --prompt "中國水墨畫風格" --save image.png
python scripts/glm_image_cli.py --prompt "賽博朋克城市" --size 1728x960 --save ~/Pictures/cyberpunk.png

Specify User ID (for content moderation) / 指定使用者 ID(用於內容稽核)

python scripts/glm_image_cli.py --prompt "..." --user-id "user_12345"

Specify Model / 指定模型

python scripts/glm_image_cli.py --prompt "..." --model glm-image
python scripts/glm_image_cli.py --prompt "..." --model cogview-4

CLI Reference / CLI 引數

python {baseDir}/scripts/glm_image_cli.py --prompt TEXT [--model MODEL] [--size SIZE] [--quality QUALITY] [--no-watermark] [--user-id ID] [--save FILE]
Parameter Required Description
--prompt, -p Yes Text description of the desired image / 圖片的文本描述
--model, -m No Model: glm-image (default), cogview-4, cogview-3-flash / 模型
--size, -s No Image size (default: 1280x1280) / 圖片尺寸
--quality, -q No Quality: hd (default) or standard / 質量
--no-watermark No Disable watermark (requires signed disclaimer) / 關閉水印
--user-id No End-user ID for content moderation (6-128 chars) / 終端使用者 ID
--save No Save generated image to local file / 儲存生成的圖片到本地檔案

Supported Sizes / 支援的尺寸

GLM-Image recommended sizes:

Size Aspect Ratio Use Case
1280x1280 1:1 Square (default)
1568×1056 3:2 Landscape / 橫向
1056×1568 2:3 Portrait / 縱向
1472×1088 ~4:3 Wide landscape
1088×1472 ~3:4 Tall portrait
1728×960 16:9 Ultra-wide landscape
960×1728 9:16 Ultra-tall portrait

Custom sizes / 自定義尺寸:

  • Width and height: 1024px - 2048px
  • Both dimensions must be multiples of 32 / 長寬均需為 32 的整數倍
  • Maximum total pixels: 2^22 (4,194,304 px) / 最大畫素數不超過 2^22

Response Format / 響應格式

Official API Response:

{
  "created": 123,
  "data": [
    {
      "url": "<string>"
    }
  ],
  "content_filter": [
    {
      "role": "assistant",
      "level": 1
    }
  ]
}

CLI Output Format:

{
  "ok": true,
  "model": "glm-image",
  "image_url": "https://open.bigmodel.cn/.../generated_image.png",
  "prompt": "一隻可愛的小貓咪,坐在陽光明媚的窗臺上,背景是藍天白雲",
  "size": "1280x1280",
  "quality": "hd",
  "created": 1710835200,
  "content_filter": [
    {
      "role": "assistant",
      "level": 3
    }
  ],
  "saved_file": "/Users/xxx/image.png",
  "error": null
}

Key fields:

  • ok — whether generation succeeded
  • model — model used for generation
  • image_url — extracted from data[0].url, temporary URL (valid 30 days)
  • prompt — the text prompt used
  • size — generated image dimensions
  • quality — hd or standard
  • created — Unix timestamp when request was created
  • content_filter — content safety analysis array (may be empty)
    • role: where the issue was detected (user/assistant/history)
    • level: severity 0-3 (0 = most severe, 3 = minor)
  • saved_file — absolute path to saved local file (if --save was used)
  • error — error details on failure

Content Safety / 內容安全

The API includes content filtering. If issues are detected, content_filter will contain entries with:

  • role: where the issue was detected (user/assistant/history)
  • level: severity 0-3 (0 = most severe, 3 = minor)

If level 0-1 detected: Generation will fail, show error to user. If level 2-3 detected: Generation may succeed, but warn user about potential issues.

Error Handling / 錯誤處理

API key not configured:

{
  "ok": false,
  "error": {
    "code": "MISSING_API_KEY",
    "message": "ZHIPU_API_KEY not configured. Get your API key at: https://bigmodel.cn/usercenter/proj-mgmt/apikeys"
  }
}

→ Show exact error to user, guide them to configure

Authentication failed (401/403):

{
  "ok": false,
  "error": {
    "code": "authentication_error",
    "message": "令牌已過期或驗證不正確",
    "status": 401
  }
}

→ API key invalid/expired → reconfigure

Rate limit (429):

{
  "ok": false,
  "error": {
    "code": "rate_limit_exceeded",
    "message": "API rate limit exceeded. Please try again later.",
    "status": 429
  }
}

→ Quota exhausted → inform user to wait or check quota

Content filter violation:

{
  "ok": false,
  "error": {
    "code": "content_filter_violation",
    "message": "Content safety check failed",
    "status": 400
  }
}

→ Explain that the prompt may contain inappropriate content

Invalid size:

{
  "ok": false,
  "error": {
    "code": "INVALID_SIZE",
    "message": "Invalid size: 512x512 for model glm-image. Must be multiple of 32, 1024-2048px, max 2^22 pixels"
  }
}

→ Guide user to use valid size from the supported list

Download failed:

{
  "ok": false,
  "error": {
    "code": "DOWNLOAD_FAILED",
    "message": "Failed to download image to image.png"
  }
}

→ Check file path permissions and disk space

Network error:

{
  "ok": false,
  "error": {
    "code": "NETWORK_ERROR",
    "message": "Network error: [Errno 8] nodename nor servname provided, or not known"
  }
}

→ Check internet connection

Prompt Tips / 提示詞技巧

Good prompts:

  • Specific details: "一隻橘色的英國短毛貓,綠色眼睛,坐在木質窗臺上"
  • Style keywords: "賽博朋克風格", "中國水墨畫", "油畫質感", "3D 渲染"
  • Lighting: "陽光明媚", "柔和的逆光", "電影感燈光"
  • Composition: "特寫鏡頭", "廣角視角", "俯視角度"

Avoid:

  • Vague descriptions: "好看的圖片"
  • Contradictory elements: "白天和夜晚同時"
  • Too many subjects: Keep focus on 1-2 main elements

🤖 AI 評測

這是一款質量較高的 AI 繪圖技能,操作簡單、文件清晰。優點是支援多種尺寸和質量模式,安全限制明確可靠,錯誤提示友好,圖片可自動儲存本地。不足是生成過程無進度顯示,缺少智慧 prompt 最佳化建議,文件以英文為主。總體來說功能實用、安全性高,適合需要快速生成高質量圖片的使用者使用。

📊 多維度評分

適應性4.9
規範性4.5
有效性4.9
可靠性4.5
可信度5

📁 包含檔案 (3 個)

📄 SKILL.md 12.4 KB
📄 _meta.json 132 B
📄 scripts/glm_image_cli.py 9.7 KB