1 #! /bin/bash 2 3 4 #BASE_DIR="/Users/jiading/Documents/basepng"; 5 #OUTPUT_DIR="/Users/jiading/Documents/output"; 6 BASE_DIR="/Users/jiading/Documents/SwordsmanApp/art/序列帧动画/实验-分段版/9_选择迷你板固定"; 7 OUTPUT_DIR="/Users/jiading/Documents/SwordsmanApp/art/序列帧动画/实验-分段版output最强压缩9"; 8 9 CUR_READ_DIR=""; 10 CUR_WRITE_DIR=""; 11 12 13 dopng(){ 14 15 readPng=$1; 16 writePng=$2; 17 fileName=$3; 18 fileName=${fileName%.*}".png"; 19 echo "图片: "$fileName; 20 21 #speed 1-11 22 23 sudo /Applications/ImageAlpha.app/Contents/MacOS/pngquant -f $readPng -o $writePng"/$fileName" --quality 10 --speed 1 --nofs --posterize 0 24 25 26 } 27 28 29 loopDir(){ 30 31 #1 进入当前读取目录 32 cd $1; 33 34 for file in *; 35 do 36 37 localReadDir=$1; 38 localWriteDir=$2; 39 40 41 if [ -d $file ];then 42 echo $file" is a dir"; 43 44 #2 进入一个目录 45 CUR_WRITE_DIR=$localWriteDir"/$file" 46 47 #3 创建对应新目录 48 echo "创建目录:"$CUR_WRITE_DIR; 49 mkdir $CUR_WRITE_DIR 50 51 #4 进入下一级遍历 52 loopDir $localReadDir"/$file" $localWriteDir"/$file" 53 54 #5 下一级遍历完之后回到当前目录 55 cd $1; 56 57 elif [ -f $file ];then 58 59 60 dopng $localReadDir"/$file" $localWriteDir "$file" 61 62 fi 63 64 done 65 66 } 67 68 main(){ 69 70 #1,删掉旧目录 71 if [ -d $OUTPUT_DIR ];then 72 echo "ouput目录已存在,立马删除"; 73 rm -rf $OUTPUT_DIR 74 fi 75 76 #2,创建output跟目录 77 mkdir $OUTPUT_DIR 78 79 80 #3,开始遍历读取 81 CUR_READ_DIR=$BASE_DIR 82 CUR_WRITE_DIR=$OUTPUT_DIR 83 loopDir $CUR_READ_DIR $CUR_WRITE_DIR 84 85 echo "=-=-=-压缩完成=-=-=-=" 86 } 87 88 main