在 Debian 下使用 GIMP 批量处理图片,常见有几种方式,从简单到进阶:
GIMP 支持无界面运行脚本(batch mode),适合简单统一操作。
gimp -i -b '(batch-convert "*.jpg" "png")' -b '(gimp-quit 0)'
不过 GIMP 默认没有 batch-convert,需要写 Script-Fu 或 Python-Fu 脚本。
~/.config/GIMP/2.10/scripts/
gimp -i -b '(script-fu-batch-resize "*.jpg" 800 600)'
适合:
Debian 安装:
sudo apt install gimp python3-gimp
示例(批量缩放):
#!/usr/bin/env python3
from gimpfu import *
def batch_resize(path, width):
for file in glob(path):
image = pdb.gimp_file_load(file, file)
pdb.gimp_image_scale(image, width, int(width * image.height / image.width))
pdb.gimp_file_save(image, image.active_layer, file, file)
register(...)
main()
运行:
gimp -i -b '(python-fu-batch-resize RUN-NONINTERACTIVE "*.jpg" 1024)'
xargs(简单批处理)如果只是调用 GIMP 处理:
ls *.jpg | xargs -I{} gimp -i -b -c '(gimp-file-load RUN-NONINTERACTIVE "{}" "{}")'
如果你只是批量处理,不一定非要用 GIMP:
sudo apt install imagemagick
mogrify -resize 800x *.jpg
| 需求 | 推荐方式 |
|---|---|
| 简单格式/尺寸 | ImageMagick |
| 必须用 GIMP | Python-Fu |
| 复杂后期 | Darktable |
| 自动化服务器 | GIMP batch + cron |
如果你能说明:
我可以给你具体可直接用的脚本。