在 Debian 上用 GIMP 做批处理,常见有几种方式,从简单到高级依次是:
GIMP 支持无界面运行,并通过 Script-Fu(Scheme)脚本批量处理。
sudo apt update
sudo apt install gimp
例如:把目录下所有 PNG 转为 JPG 并缩放为 800px 宽。
新建文件 batch-resize.scm:
(define (batch-resize pattern width)
(let* ((filelist (cadr (file-glob pattern 1))))
(while (not (null? filelist))
(let* ((filename (car filelist))
(image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-get-active-layer image))))
(gimp-image-scale image width (round (* width (/ (car (gimp-image-height image)) (car (gimp-image-width image))))))
(file-jpeg-save RUN-NONINTERACTIVE image drawable (string-append filename ".jpg") (string-append filename ".jpg") 0.9 0 0 0 "" 0 1 0 0)
(gimp-image-delete image))
(set! filelist (cdr filelist)))))
gimp -i -b '(batch-resize "*.png" 800)' -b '(gimp-quit 0)'
参数说明:
-i:无界面-b:执行 Script-Fu(gimp-quit 0):退出gimp-console(更轻量)Debian 中可直接用:
gimp-console -i -b '(script)' -b '(gimp-quit 0)'
如果你不想写脚本:
sudo apt install gimp-plugin-registry
启动 GIMP → Filters → Batch Image Manipulation
功能包括:
✅ 适合不熟悉脚本的用户
如果你只是做批量图像处理,其实更推荐:
sudo apt install imagemagick
convert *.png -resize 800x output/%03d.jpg
mogrifymogrify -resize 800x -format jpg *.png
| 需求 | 推荐方式 |
|---|---|
| 简单格式转换 | ImageMagick |
| 复杂图层/滤镜 | GIMP Script-Fu |
| 不想写代码 | BIMP |
| 服务器无界面 | gimp-console |
如果你能告诉我:
我可以直接帮你写可用的 Debian 批处理脚本。