Community影像github.com

greg

快速、本地、可自訂的 AI 去背工具與圖片格式轉換器。當被要求去背、製作透明 Logo/圖示、批次處理圖片或在本機轉換圖片格式時使用。

greg 是什麼?

`greg` 是一個本地端的 AI 去背與圖片轉換命令列工具與 MCP 伺服器。它支援一行指令完成背景移除、資料夾移動、重新命名、格式轉換,並提供 NDJSON 串流進度與完成鉤子功能。此工具特別適合開發者與 AI 代理(如 Claude Code、Cursor)使用,因為它可以完全在本地執行,無需上傳圖片至外部服務,確保資料隱私。greg 提供多種預設模型(如快速、Logo、人像、商品、動漫),可根據不同場景選擇最佳模型。它支援常見的透明格式(PNG、WebP、AVIF)與不透明格式(JPG、PDF),並提供豐富的邊緣處理、裁剪、縮放選項。其 MCP 伺服器模式可讓其他 AI 工具直接呼叫去背、批次處理與圖片轉換功能,實現無縫整合。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/tensorGT/greg/tree/HEAD

Installed? Explore more 影像 skills: steipete/songsee, affaan-m/frontend-design, mattpocock/improve-codebase-architecture · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

greg — 代理使用指南

greg 是一個本地 AI 背景移除與圖片轉換的 CLI + MCP 伺服器。 它支援一行指令的背景移除、資料夾移動、重新命名、格式轉換、NDJSON 串流進度以及完成鉤子。

快速食譜 (CLI)

當以代理身份呼叫 greg 時,請始終傳入 --json -y:

  • --json 將每個 JSON 物件串流成一行 (NDJSON) 到 stdout 並立即刷新。
  • -y (--yes) 自動確認下載模型(若尚未快取),然後立即繼續。

1. 一行指令完成去背、移動、重新命名與轉換

greg remove "path/to/logo.jpg" --out-dir "./assets" --name "brand_logo" --ext webp --preset logo --json -y

2. 批次處理圖片列表、glob 或 @filelist.txt

greg remove img1.png img2.jpg --out-dir "./clean" --pattern "{stem}_nobg" --ext png --workers 2 --json -y
greg remove @batch.txt --out-dir "./clean" --ext webp --json -y

3. 背景等待 / 完成時觸發

在背景執行 greg,並選擇:

  • 監看其 stdout 的 NDJSON 串流,或
  • 傳入 --done-file ./job.done.json(完成時原子寫入),或
  • 傳入 --webhook http://localhost:PORT/hook(完成時 HTTP POST 摘要 JSON)。
greg remove ./raw/*.png --out-dir ./out --done-file ./out/job.done.json --json -y

4. 無 AI 的格式轉換 / 裁剪 / 縮放

greg convert "./assets/brand_logo.png" --out-dir "./public" --name "favicon" --ext ico --trim --json

預設與模型

預設模型最佳用途
fast (預設)u2netp (~5 MB)超快通用摳圖、圖標、大量預覽
logoisnet-general-use (~178 MB)邊緣銳利、光暈去除、自動裁剪 + 8px 內距
portraitbirefnet-general-lite (~214 MB)人物、頭髮、毛髮、柔邊
productisnet-general-use (~178 MB)電商產品、自動裁剪 + 16px 內距
animeisnet-anime (~176 MB)插畫、貼圖、動漫

可用模型 (--model):u2netp (預設), silueta, u2net, isnet-general-use, isnet-anime, birefnet-general-lite, birefnet-general。

支援的輸出格式 (--ext)

  • 含透明通道:png, webp (--quality 100 為無損), avif, tiff, tga, ico (多尺寸圖標)
  • 不透明 (合成到 --bg-color 上,預設 white):jpg, jpeg, bmp, pdf

常用旗標

  • --out-dir, -o <dir>:輸出資料夾(預設為輸入檔案所在資料夾)
  • --name, -n <stem>:確切的輸出檔名(不含副檔名)
  • --pattern, -p <pat>:批次處理的檔名模式({stem}, {index}, {model};預設 {stem}_nobg)
  • --on-exists [suffix|overwrite|skip]:檔案衝突處理(預設 suffix)
  • --trim / --no-trim:緊密裁剪透明邊緣至主體
  • --pad <px>:裁剪後主體周圍的統一內距
  • --resize <WxH>:保持比例放入指定方框內(例如 512x512 或 512)
  • --bg-color <color>:transparent, white, black, 或 #RRGGBB / #RRGGBBAA
  • --defringe <0.0..1.0>:邊緣顏色去污染(消除白/暗光暈)
  • --erode <px> / --feather <px> / --threshold <0..255>:邊緣微調
  • --dry-run:預覽解析後的輸入 -> 輸出路徑,但不實際寫入檔案

NDJSON 串流結構 (--json)

  • {"event": "download_start", "model": "...", "size_mb": 178} (僅當未快取時)
  • {"event": "download_progress", "model": "...", "percent": 40, ...}
  • {"event": "download_done", "model": "..."}
  • {"event": "start", "action": "remove", "total": 2, "model": "u2netp"}
  • {"event": "progress", "completed": 1, "total": 2, "input": "...", "output": "...", "status": "ok", "ms": 210}
  • {"event": "done", "total": 2, "succeeded": 2, "skipped": 0, "failed": 0, "elapsed_ms": 430, "outputs": [...]}

退出碼

  • 0:所有檔案處理成功
  • 1:部分失敗(請檢查最終 done JSON 中的 errors)
  • 2:參數無效或致命設定錯誤

原生 MCP 伺服器

greg 也可以作為 stdio MCP 伺服器 (greg mcp) 執行,暴露以下工具:

  • list_models
  • remove_background
  • batch_remove_background
  • convert_image

相關技能