You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
########## name:图片压缩脚本 ##########
|
|
|
|
########## author:xiaoz<xiaoz93@outlook.com> ##########
|
|
|
|
########## from: ##########
|
|
|
|
########## update:2019-08-23 ##########
|
|
|
|
|
|
|
|
#导入环境变量
|
|
|
|
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/bin:/sbin
|
|
|
|
export PATH
|
|
|
|
|
|
|
|
#设置图片绝对路径
|
|
|
|
imgpath=''
|
|
|
|
#最低图片大小,高于此大小的图片才会进行压缩
|
|
|
|
min_size='100k'
|
|
|
|
|
|
|
|
#判断图片路径是否为空
|
|
|
|
if [ $imgpath -eq '' ]
|
|
|
|
then
|
|
|
|
imgpath=$1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $imgpath -eq '' ]
|
|
|
|
then
|
|
|
|
echo 'The image path cannot be empty!'
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#压缩png/jpg/bmp图像
|
|
|
|
function com_img(){
|
|
|
|
#使用optipng压缩.png和.bmp
|
|
|
|
find {$1} -mmin -60 -size +{$2} -name '*.png' -exec optipng -o3 {} \;
|
|
|
|
find {$1} -mmin -60 -size +{$2} -name '*.bmp' -exec optipng -o3 {} \;
|
|
|
|
|
|
|
|
#使用jpegoptim压缩.jpg
|
|
|
|
find {$1} -mmin -60 -size +{$2} -name '*.jpg' -exec jpegoptim -m 80 {} \;
|
|
|
|
find {$1} -mmin -60 -size +{$2} -name '*.jpeg' -exec jpegoptim -m 80 {} \;
|
|
|
|
}
|
|
|
|
|
|
|
|
#调用压缩函数
|
|
|
|
com_img $imgpath $min_size
|