From 5a5f90e62d664f2660a8059cad7072439c248b3b Mon Sep 17 00:00:00 2001 From: xiaoz Date: Fri, 23 Aug 2019 12:22:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=84=9A=E6=9C=AC=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- img_compress.sh | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/img_compress.sh b/img_compress.sh index a283f79..5e1d2e6 100644 --- a/img_compress.sh +++ b/img_compress.sh @@ -1,6 +1,7 @@ +#!/bin/bash ########## name:图片压缩脚本 ########## ########## author:xiaoz ########## -########## from: ########## +########## Blog:https://www.xiaoz.me/ ########## ########## update:2019-08-23 ########## #导入环境变量 @@ -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 {} \; } #调用压缩函数