在Ubuntu上使用GIMP进行批量处理的三种高效方式
一、使用BIMP插件图形化批量处理(推荐)
git clone https://gitcode.com/gh_mirrors/gi/gimp-plugin-bimp
cd gimp-plugin-bimp
make && sudo make install
二、使用命令行脚本批量处理(无界面、可自动化)
#!/usr/bin/env bash
for f in *.jpg; do
[ -e "$f" ] || continue
gimp-console -i -b "(batch-convert-to png \"$f\" \"${f%.jpg}.png\")" -b "(gimp-quit 0)"
done
#!/usr/bin/env bash
for f in *.jpg; do
[ -e "$f" ] || continue
gimp-console -i -b "(let* ((img (car (gimp-file-load RUN-NONINTERACTIVE \"$f\" \"$f\")))
(w (car (gimp-image-width img)))
(h (car (gimp-image-height img))))
(gimp-image-scale img (* w 0.5) (* h 0.5))
(gimp-file-save RUN-NONINTERACTIVE img (car (gimp-image-get-active-layer img)) \"${f%.jpg}_scaled.jpg\" \"${f%.jpg}_scaled.jpg\")
(gimp-image-delete img))" -b "(gimp-quit 0)"
done
三、何时考虑非GIMP工具
# 将所有JPG缩小为50%并输出到output目录
mkdir -p output
convert *.jpg -resize 50% output/img_%03d.jpg
四、实用建议与常见问题