Answers:
(主要供个人将来参考),使用ImageMagick:
convert -trim image.jpg image.jpg
要修剪/自动裁剪整个目录:
for a in *.jpg; do convert -trim "$a" "$a"; done
或使用find:
find -name "*.jpg" -exec convert -trim "{}" "{}" \;
我已经有一段时间没有使用过了,但希望能有所帮助。制作一个gimp批处理脚本(我称为minecrop-png.scm),并将其放在〜/ .gimp-2.6 / scripts /中。
(define (crop-png filename)
(let*
(
(image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-get-active-layer image)))
)
; crop the image
(plug-in-autocrop RUN-NONINTERACTIVE image drawable)
; save in original png format
(file-png-save RUN-NONINTERACTIVE image drawable filename filename
0 6 0 0 0 1 1)
; clean up the image
(gimp-image-delete image)
)
)
然后保存此外壳脚本(例如pngcrop.sh),并在png文件上调用它,如下所示:'pngcrop.sh * .png'
#!/bin/bash
if [ $# -le 0 ]; then
echo
echo "Usage: $(basename $0) file1.png [file2.png ...]"
echo
echo " This script uses gimp to autocrop PNG files and"
echo " save them to PNG format. You must have"
echo " crop-png.scm installed in your gimp "
echo " scripts directory."
echo
exit 1
fi
# set the filelist
files=$*
# # set the base command
# CMD="gimp -i -b "
# loop and add each file
for i in ${files[*]} ; do
# #echo $i
# ARGS="\"(crop-png \\\"$i\\\")\""
# CMD="$CMD $ARGS"
gimp -i -b "(crop-png \"$i\")" -b "(gimp-quit 0)"
done
# # add the end to quit
# TAIL="-b \"(gimp-quit 0)\""
# CMD="$CMD $TAIL"
#
# #echo $CMD
# eval $CMD
mogrify
将执行与convert相同的工作,但将覆盖原始副本而不是进行复制。