Skip to content

GIMP 实战教程

GIMP 是最强大的开源图片编辑器。通过 CLI-Anything,AI Agent 可以直接操控 GIMP 完成各种图片处理任务。


Terminal window
# 安装 CLI-Hub
pip install cli-anything-hub
# 安装 GIMP CLI
cli-hub install gimp
# 验证
cli-hub info gimp

场景:把产品目录下 50 张图片统一裁剪为 800x800 正方形。

Terminal window
# 启动 GIMP CLI
cli-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

在 Claude Code / OpenClaw 中说:

把 ./products/ 下所有 JPG 图片裁剪为 800x800 正方形(居中裁剪),
导出到 ./output/,质量 90%

Agent 会自动生成批量脚本:

import os
import 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}")

场景:给所有图片添加右下角半透明水印。

Terminal window
# 在 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.jpg
给 ./photos/ 下所有图片添加右下角水印 "© 2026 MyBrand",
白色字体,透明度 30%,字号 24px,导出到 ./watermarked/

场景:将 PNG 转为 WebP(减小体积)。

Terminal window
cli-anything-gimp image convert --input ./hero.png --format WebP --quality 85 --output ./hero.webp

批量版本:

Terminal window
# Bash 一行搞定
for f in ./images/*.png; do
cli-anything-gimp image convert --input "$f" --format WebP --quality 85
done

场景:批量将照片调成暖色调。

Terminal window
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灰度-

操作GIMP GUI(手动)GIMP CLI + AI(自动)
裁剪 50 张图~25 分钟~2 分钟
添加水印 100 张~50 分钟~3 分钟
格式转换 200 张~60 分钟~5 分钟
批量调色 50 张~40 分钟~4 分钟

效率提升:10-15 倍 🚀


CLI-Anything 不会自动安装 GIMP 本体。需要先安装:

  • Windows下载安装包
  • macOSbrew install --cask gimp
  • Linuxsudo apt install gimp / sudo dnf install gimp

首次启动较慢(加载插件),后续操作会快很多。建议使用 cli-hub launch gimp 保持 REPL 长连接。

CLI 支持断点续传:

Terminal window
cli-anything-gimp batch resume --log ./batch-progress.json