ImageMagick批量缩小相机导出的原始图片

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/bin/bash
if [ $# -ne 2 ]; then
	echo "Usage: $0 directory. \nExample:$0 ./apple ./processed "
	exit 0
fi
[ ! -d "$2" ] && mkdir "$2"
if [ ! -d "$1" ]; then
	echo "Directory $1 is not found!"
	exit 0
elif [ "$(ls $1)" = "" ]; then
	echo "Directory $1 is empty!"
	exit 0
fi 
if [ ! -d "$2" ]; then
	echo "Create Directory $2 failed!!"
	exit 0
fi 
SRC="${1%/}" # 原目录,删除尾部斜杠
DST="${2%/}" # 处理后的目录,删除尾部斜杠

for f in $(ls $1); do
	ext=$(echo "${f##*.}" |tr '[A-Z]' '[a-z]')
	case "$ext" in
		'jpg'|'jpeg'|'png'|'gif')
		echo -n "Image : $f"
		width=$(identify -format "%w" $SRC/$f)
		if [ $width -le 648 ];then
			echo "	IG" # 忽略宽度尺寸小于 648 的图片
		else
			nf="${f%.*}.$ext"
			convert -auto-orient -resize 25%x25% $SRC/$f $DST/$nf
			echo "	OK" 
		fi	
		;;
		*)
		echo   "Ignore: $f"
		;;
	esac
done