Community影像github.com

yb2460/cli-anything-photoshop

透過 Windows COM 自動化操控 Adobe Photoshop 的 CLI 工具,支援專案管理、圖層操作、選區控制、文字編輯、影像調整與多格式匯出。

cli-anything-photoshop 是什麼?

此技能提供一個命令列工具,透過 Windows COM 自動化介面操控 Adobe Photoshop。它允許 AI 代理程式以結構化方式執行專案管理、圖層操作、選區控制、文字編輯與匯出等任務,非常適合需大量處理影像的工作流程。支援 `--json` 輸出模式,方便 AI 代理解析結果;`--dry-run` 模式可預覽變更而不實際儲存。主要支援 Windows 10/11 與 Adobe Photoshop 2023 以上版本,需要 Python 3.10 以上及 pywin32 套件。內部採用 ComBridge 單例模式與 Photoshop.Application COM 物件溝通,封裝了最常用的操作。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/yb2460/harness-anything/tree/master/photoshop-harness/skills/cli-anything-photoshop

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

在你喜歡的 AI 中提問

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

說明文件

CLI-Anything Photoshop

透過 Windows COM 自動化介面操控 Adobe Photoshop 的命令列工具。

前置條件

  • Windows 10/11
  • Adobe Photoshop 2023+(需註冊 COM 介面)
  • Python 3.10+ 及 pywin32 套件

安裝

cd photoshop-harness/agent-harness
pip install -e .

安裝後可使用 cli-anything-photoshop 命令。

命令結構

cli-anything-photoshop [--json] [--project <path>] [--dry-run] <command-group> <command> [options]

全域選項

選項描述
--json以 JSON 格式輸出(供 AI Agent 解析)
--project <path>自動開啟或建立 PSD 專案檔案
--dry-run執行命令但不儲存到磁碟

命令組

project — 專案管理

命令選項描述
new <path>-w width, -h height, -r resolution, -m mode, -b bg-color建立新 PSD
open <path>開啟 PSD 檔案
save [path]儲存文件
close--no-save關閉文件

document — 文件操作

命令選項描述
info文件資訊
resize-w width, -h height, -r resolution調整尺寸
canvas-w width, -h height, -a anchor調整畫布
crop--left --top --right --bottom裁切
rotate-a angle旋轉畫布
flip-d direction翻轉畫布
mode-m mode更改色彩模式
trim-t type裁切邊緣

layer — 圖層操作

命令選項描述
add-n name, -t type, -o opacity, -b blend新增圖層
delete-n name刪除圖層
duplicate-n name, --new-name name複製圖層
rename--old name, --new name重新命名
show / hide-n name顯示/隱藏
opacity-n name, -o opacity設定透明度
blend-n name, -m mode設定混合模式
list列出所有圖層
reorder-n name, -p position調整順序
merge-n name, --with-layer name合併圖層

selection — 選區操作

命令選項描述
all全選
none取消選取
invert反轉選取
feather-r radius羽化
expand-p pixels擴張
contract-p pixels收縮
border-w width邊框選取
rect--left --top --right --bottom矩形選取
fill-c color, -o opacity填充選取

text — 文字操作

命令選項描述
add-t text, -f font, -s size, -c color新增文字
edit-n name, -t text, -f font, -s size, -c color編輯文字
info-n name文字資訊

export — 匯出

命令選項描述
save <path>-f format, -q quality, -w width, -h height匯出檔案

repl

命令描述
repl啟動互動式 REPL 模式

使用範例

AI Agent 用法(--json 模式)

# 建立新專案並取得 JSON 輸出
cli-anything-photoshop --json project new -w 800 -h 600 poster.psd

# 新增文字圖層
cli-anything-photoshop --json --project poster.psd text add -t "Hello World" -f Arial -s 48 -c "#FF0000"

# 列出所有圖層(JSON 格式)
cli-anything-photoshop --json --project poster.psd layer list

# 匯出為 PNG
cli-anything-photoshop --json --project poster.psd export save -f png output.png

# 預覽(不儲存)
cli-anything-photoshop --dry-run --project poster.psd layer add -n "draft" --type text

人工使用

# 開啟 PSD,互動編輯
cli-anything-photoshop --project work.psd layer list

# 啟動 REPL
cli-anything-photoshop repl

Agent 使用指南

  1. 始終使用 --json 標誌 取得結構化輸出
  2. 使用 --dry-run 預覽,確認後再正式儲存
  3. 錯誤處理:退出碼非零時檢查 stderr 中的 JSON 錯誤物件
  4. 專案狀態:使用 --project 自動管理檔案開啟/儲存
  5. REPL 模式:適合多步驟互動式操作,減少 Photoshop 程序啟動開銷

Photoshop COM 架構

CLI 命令 → Click CLI → Core 模組 → ComBridge (單例) → Photoshop.Application COM → Photoshop 引擎

Photoshop 透過 Windows COM 介面暴露全部編輯能力。本 harness 封裝了最常用的操作。如需擴充,參考 Adobe Photoshop COM 文件新增方法到 utils/com_bridge.py。

Individual skills in this repo

This repo contains 1 individual skill — each has its own dedicated page.

相關技能