#! /bin/bash #BASE_DIR="/Users/jiading/Documents/basepng";
#OUTPUT_DIR="/Users/jiading/Documents/output";
BASE_DIR="/Users/jiading/Documents/SwordsmanApp/art/序列帧动画/实验-分段版/9_选择迷你板固定";
OUTPUT_DIR="/Users/jiading/Documents/SwordsmanApp/art/序列帧动画/实验-分段版output最强压缩9"; CUR_READ_DIR="";
CUR_WRITE_DIR=""; dopng(){ readPng=$;
writePng=$;
fileName=$;
fileName=${fileName%.*}".png";
echo "图片: "$fileName; #speed - sudo /Applications/ImageAlpha.app/Contents/MacOS/pngquant -f $readPng -o $writePng"/$fileName" --quality --speed --nofs --posterize } loopDir(){ # 进入当前读取目录
cd $; for file in *;
do localReadDir=$;
localWriteDir=$; 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 $; elif [ -f $file ];then dopng $localReadDir"/$file" $localWriteDir "$file" fi done } main(){ #,删掉旧目录
if [ -d $OUTPUT_DIR ];then
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