Created
March 4, 2021 08:29
-
-
Save wuyongrui/0fb5f33fab8ef77cd2bedb7a29d22899 to your computer and use it in GitHub Desktop.
compress image by pngquant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/Bash | |
| pngfile=".png" | |
| jpgfile=".jpg" | |
| ignorefile='__ic' #ignore compress | |
| rootpath='src/assets' | |
| read_dir(){ | |
| for file in `ls -a $1` | |
| do | |
| if [ -d $1"/"$file ] | |
| then | |
| if [[ $file != '.' && $file != '..' ]] | |
| then | |
| read_dir $1"/"$file | |
| fi | |
| else | |
| if [[ $file == *$pngfile ]] || [[ $file == *$jpgfile ]] | |
| then | |
| if [[ $file =~ $ignorefile ]] | |
| then | |
| echo "忽略:"$1"/"$file | |
| else | |
| # process | |
| echo "压缩:"$1"/"$file | |
| ./pngquant --quality=75 --skip-if-larger --ext=.png --force $1"/"$file | |
| fi | |
| else | |
| echo "忽略:"$1"/"$file | |
| fi | |
| fi | |
| done | |
| } | |
| echo "Begin" | |
| befor_size=$(du -hs $rootpath | cut -f1) | |
| read_dir $rootpath | |
| echo "Done" | |
| after_size=$(du -hs $rootpath | cut -f1) | |
| echo $befor_size "->" $after_size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment