等比例批量生成缩略图
使用 graphicsmagick
graphicsmagick
安装
# ubuntu
apt-get install graphicsmagick
# macos
brew install GraphicsMagick
# 查看安装信息
# which gm && unalias gm
gm -version
图片压缩命令
gm convert input.jpg -thumbnail '240x135' output_1.jpg
处理脚本
src_path=. # 压缩源图输入目录
tgt_path=. # 压缩源图输出目录
# 方法一
function make_thumbnail {
for file in `ls $1`
do
echo $file
image="${1}/${file}"
thumb="${2}/${file}"
if [ -d ${image} ]
then
mkdir -p ${thumb}
make_thumbnail ${image} ${thumb}
elif [ ! -f ${thumb} ]
then
echo $thumb
# gm convert -resize "240x135" -quality 85 -strip ${image} ${thumb}
gm convert -thumbnail '240x135' -strip ${image} ${thumb}
else
echo "already exists"
fi
echo "***************"
done
}
make_thumbnail $src_path $tgt_path
# 方法二
find $src_path -size +20k | xargs -i gm convert -thumbnail '240x135' -strip {} $tgt_path/{}