From e6c7e7793c79a42d92267cc72180a11ba9c3f671 Mon Sep 17 00:00:00 2001 From: xiaoz Date: Fri, 23 Aug 2019 11:08:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=8E=8B=E7=BC=A9=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- img_compress.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 img_compress.sh diff --git a/img_compress.sh b/img_compress.sh new file mode 100644 index 0000000..ebd43cc --- /dev/null +++ b/img_compress.sh @@ -0,0 +1,41 @@ +########## name:图片压缩脚本 ########## +########## author:xiaoz ########## +########## from:xiaoz ########## +########## 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