需要安装软件
#! /bin/bash
export LANG=C.UTF-8
#BASE_DIR="/Users/jiading/Documents/basepng";
#OUTPUT_DIR="/Users/jiading/Documents/output";
BASE_DIR="/Users/zhaoqidong/Downloads/漫画/16-18"
OUTPUT_DIR="/Users/zhaoqidong/Downloads/漫画/yasuode"
CUR_READ_DIR=""
CUR_WRITE_DIR=""
dopng() {
readPng=$1
writePng=$2
fileName=$3
fileName=${fileName%.*}".png"
echo "图片: "$fileName
#speed 1-11
/Users/zhaoqidong/Downloads/pngquant/pngquant -f $readPng -o $writePng"/$fileName" --quality 100 --speed 1 --nofs
}
loopDir() {
# 进入当前读取目录
cd $1
for file in *; do
localReadDir=$1
localWriteDir=$2
if [ -d $file ]; then
echo $file" is a dir"
# 进入一个目录
CUR_WRITE_DIR=$localWriteDir"/$file"
# 创建对应新目录
echo "创建目录:"$CUR_WRITE_DIR
mkdir $CUR_WRITE_DIR
# 进入下一级遍历
loopDir $localReadDir"/$file" $localWriteDir"/$file"
# 下一级遍历完之后回到当前目录
cd $1
elif [ -f $file ]; then
dopng $localReadDir"/$file" $localWriteDir "$file"
fi
done
}
main() {
#,删掉旧目录
if [ -d $OUTPUT_DIR ]; then
echo $OUTPUT_DIR;
echo "ouput目录已存在,立马删除"
rm -rf $OUTPUT_DIR
fi
#,创建output跟目录
mkdir $OUTPUT_DIR
#,开始遍历读取
CUR_READ_DIR=$BASE_DIR
CUR_WRITE_DIR=$OUTPUT_DIR
loopDir $CUR_READ_DIR $CUR_WRITE_DIR
echo "=-=-=-压缩完成=-=-=-="
}
main