|
|
|
@ -1,6 +1,7 @@
@@ -1,6 +1,7 @@
|
|
|
|
|
#!/bin/bash |
|
|
|
|
########## name:图片压缩脚本 ########## |
|
|
|
|
########## author:xiaoz<xiaoz93@outlook.com> ########## |
|
|
|
|
########## from: ########## |
|
|
|
|
########## Blog:https://www.xiaoz.me/ ########## |
|
|
|
|
########## update:2019-08-23 ########## |
|
|
|
|
|
|
|
|
|
#导入环境变量 |
|
|
|
@ -13,28 +14,26 @@ imgpath=''
@@ -13,28 +14,26 @@ imgpath=''
|
|
|
|
|
min_size='100k' |
|
|
|
|
|
|
|
|
|
#判断图片路径是否为空 |
|
|
|
|
if [ $imgpath -eq '' ] |
|
|
|
|
if [ -z $imgpath ] |
|
|
|
|
then |
|
|
|
|
imgpath=$1 |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
if [ $imgpath -eq '' ] |
|
|
|
|
if [ -z $imgpath ] |
|
|
|
|
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 {} \; |
|
|
|
|
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 {} \; |
|
|
|
|
find $1 -mmin -60 -size +$2 -name '*.jpg' -exec jpegoptim -m 80 {} \; |
|
|
|
|
find $1 -mmin -60 -size +$2 -name '*.jpeg' -exec jpegoptim -m 80 {} \; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#调用压缩函数 |
|
|
|
|