linux shell批量压缩某个目录下图片大小

linux shell批量压缩某个目录下图片大小

#!/bin/sh
read -p "Input Path:" SPATH
maxsize=$((1024*200))
FILELIST () {
        filelist=`ls $SPATH`
        for filename in $filelist; do
                fname=$(basename "$filename")
                ex="${fname##*.}"
                if [ -f $filename ] && [ $ex = 'jpg' -o $ex = 'jpeg' -o $ex = 'png' -o $ex = 'JPG' -o $ex = 'JPEG' -o $ex = 'PNG' ] ;then
                        #echo $filename
                        COMPRESS $filename
                elif [ -d $filename ];then
                        cd $filename
                        SPATH=`pwd`
                        FILELIST
                        cd ..
                fi

        done
}
COMPRESS () {
        imgpath=$1
        filesize=`ls -l $imgpath | awk '{ print $5 }'`
        if [ $filesize -ge $maxsize ]; then
                #convert -quality 85% $imgpath $imgpath
                echo $imgpath
        fi
}
cd $SPATH
FILELIST
echo "Done."




你可能感兴趣的:(linux shell批量压缩某个目录下图片大小)