GIMP 实战教程
🎨 GIMP CLI 实战教程
Section titled “🎨 GIMP CLI 实战教程”GIMP 是最强大的开源图片编辑器。通过 CLI-Anything,AI Agent 可以直接操控 GIMP 完成各种图片处理任务。
📦 安装 GIMP CLI
Section titled “📦 安装 GIMP CLI”# 安装 CLI-Hubpip install cli-anything-hub
# 安装 GIMP CLIcli-hub install gimp
# 验证cli-hub info gimp🎯 实战 1:批量裁剪图片
Section titled “🎯 实战 1:批量裁剪图片”场景:把产品目录下 50 张图片统一裁剪为 800x800 正方形。
# 启动 GIMP CLIcli-hub launch gimp
# 单张裁剪> image open --path ./product-001.jpg> image crop --width 800 --height 800 --center> export file --path ./output/product-001.jpg --quality 90> image close用 AI Agent 一键完成
Section titled “用 AI Agent 一键完成”在 Claude Code / OpenClaw 中说:
把 ./products/ 下所有 JPG 图片裁剪为 800x800 正方形(居中裁剪),导出到 ./output/,质量 90%Agent 会自动生成批量脚本:
import osimport subprocess
input_dir = "./products/"output_dir = "./output/"os.makedirs(output_dir, exist_ok=True)
for f in sorted(os.listdir(input_dir)): if f.lower().endswith(('.jpg', '.jpeg')): subprocess.run([ 'cli-anything-gimp', 'image', 'crop', '--input', os.path.join(input_dir, f), '--width', '800', '--height', '800', '--center', '--output', os.path.join(output_dir, f), '--quality', '90' ]) print(f"✅ {f}")🎯 实战 2:批量添加水印
Section titled “🎯 实战 2:批量添加水印”场景:给所有图片添加右下角半透明水印。
# 在 CLI REPL 中> image open --path ./photo.jpg> layer add --type text --text "© 2026 MyBrand" --position bottom-right --opacity 30 --font-size 24 --color "#FFFFFF"> export file --path ./output/photo.jpgAI Agent 版本
Section titled “AI Agent 版本”给 ./photos/ 下所有图片添加右下角水印 "© 2026 MyBrand",白色字体,透明度 30%,字号 24px,导出到 ./watermarked/🎯 实战 3:图片格式批量转换
Section titled “🎯 实战 3:图片格式批量转换”场景:将 PNG 转为 WebP(减小体积)。
cli-anything-gimp image convert --input ./hero.png --format WebP --quality 85 --output ./hero.webp批量版本:
# Bash 一行搞定for f in ./images/*.png; do cli-anything-gimp image convert --input "$f" --format WebP --quality 85done🎯 实战 4:自动调色 + 滤镜
Section titled “🎯 实战 4:自动调色 + 滤镜”场景:批量将照片调成暖色调。
cli-anything-gimp filter apply --name "warm-tone" --intensity 0.7 --input ./photo.jpg --output ./warm-photo.jpg可用滤镜列表:
| 滤镜名 | 说明 | 参数 |
|---|---|---|
warm-tone | 暖色调 | --intensity (0-1) |
cool-tone | 冷色调 | --intensity (0-1) |
gaussian-blur | 高斯模糊 | --radius (px) |
sharpen | 锐化 | --amount (0-1) |
vignette | 暗角 | --softness (0-1) |
grayscale | 灰度 | - |
📊 性能对比
Section titled “📊 性能对比”| 操作 | GIMP GUI(手动) | GIMP CLI + AI(自动) |
|---|---|---|
| 裁剪 50 张图 | ~25 分钟 | ~2 分钟 |
| 添加水印 100 张 | ~50 分钟 | ~3 分钟 |
| 格式转换 200 张 | ~60 分钟 | ~5 分钟 |
| 批量调色 50 张 | ~40 分钟 | ~4 分钟 |
效率提升:10-15 倍 🚀
🐛 常见问题
Section titled “🐛 常见问题”Q: GIMP 没有安装
Section titled “Q: GIMP 没有安装”CLI-Anything 不会自动安装 GIMP 本体。需要先安装:
- Windows:下载安装包
- macOS:
brew install --cask gimp - Linux:
sudo apt install gimp/sudo dnf install gimp
Q: CLI 启动 GIMP 很慢
Section titled “Q: CLI 启动 GIMP 很慢”首次启动较慢(加载插件),后续操作会快很多。建议使用 cli-hub launch gimp 保持 REPL 长连接。
Q: 批量处理中途出错
Section titled “Q: 批量处理中途出错”CLI 支持断点续传:
cli-anything-gimp batch resume --log ./batch-progress.json