Skip to content

Instantly share code, notes, and snippets.

@NickJian
Last active June 15, 2017 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NickJian/ba13f55373791983b3cdf71377b6a6a4 to your computer and use it in GitHub Desktop.
Save NickJian/ba13f55373791983b3cdf71377b6a6a4 to your computer and use it in GitHub Desktop.
while [[ true ]]; do
echo "pull latest images"
git clone <git path> --branch <branch name> --single-branch
# step1, run imageOtim
./imageoptim -s -d ./<res path>
# step2, convert webp
# webp is not supported until 4.3 (api 18)
# echo "locate all image files"
# find . -path "./<res path>/*" -type f \( -iname "*.png" -o -iname "*.PNG" -o -iname "*.jpg" -o -iname "*.JPG" \) -print0 | while IFS= read -r -d $'\0' file;
# do
# base="${file:0:${#file}-4}"
# webpfile="${file:0:${#file}-4}.webp"
#
# if ! [[ $file == *".9"* ]] && [[ $file == *".png"* ]]
# then
# echo
# cwebp -q 70 "$file" -o "$webpfile" -m 6 -quiet
#
# I=$(stat -f "%z" $webpfile)
# J=$(stat -f "%z" $file)
#
# echo "convert $file to webp (webp size:" $I " original size:" $J ")"
#
# # delete the WebP file if it is equal size or larger than the original PNG
# if [ $I -gt $J ]
# then
# echo "delete WebP file that is no smaller than PNG"
# rm -f "$base".webp
# else
# echo "replace png with smaller webp"
# rm -f "$file"
# fi
# fi
# done
#
echo "push image changes..."
git add -A
git commit -am "weekly image triming"
git push origin <branch name>
cd ..
echo "job done, see you next week"
sleep 604800
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment