Skip to content

Instantly share code, notes, and snippets.

@wuyongrui
Created March 4, 2021 08:29
Show Gist options
  • Select an option

  • Save wuyongrui/0fb5f33fab8ef77cd2bedb7a29d22899 to your computer and use it in GitHub Desktop.

Select an option

Save wuyongrui/0fb5f33fab8ef77cd2bedb7a29d22899 to your computer and use it in GitHub Desktop.
compress image by pngquant
#! /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