2015-09-27 14:03:31 +03:00
|
|
|
#!/usr/bin/env bash
|
2013-04-13 12:01:13 +04:00
|
|
|
|
2020-04-21 14:50:26 +03:00
|
|
|
CHECK_DIR='../'
|
|
|
|
if ! [ "$SERVER_VERSION" ]; then
|
|
|
|
CHECK_DIR=$1
|
|
|
|
fi
|
|
|
|
|
2013-04-13 12:01:13 +04:00
|
|
|
function recursive_optimize_images() {
|
2020-04-21 14:33:11 +03:00
|
|
|
cd "$1" || return
|
2020-04-21 14:50:26 +03:00
|
|
|
DIR_NAME=${PWD##*/}
|
|
|
|
|
|
|
|
if [[ "$DIR_NAME" == "node_modules" ]]; then
|
|
|
|
return
|
|
|
|
elif [[ "$DIR_NAME" == "tests" ]]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Optimize all PNGs
|
|
|
|
for png in *.png
|
|
|
|
do
|
|
|
|
[[ -e "$png" ]] || break
|
|
|
|
|
|
|
|
optipng -o6 -strip all "$png"
|
|
|
|
done
|
2020-04-21 14:30:53 +03:00
|
|
|
|
2020-04-21 14:50:26 +03:00
|
|
|
# Optimize all JPGs
|
|
|
|
for jpg in *.jpg
|
|
|
|
do
|
|
|
|
[[ -e "$jpg" ]] || break
|
|
|
|
|
|
|
|
jpegoptim --strip-all "$jpg"
|
|
|
|
done
|
2020-04-21 14:30:53 +03:00
|
|
|
|
|
|
|
# Optimize all SVGs
|
2020-04-21 14:33:11 +03:00
|
|
|
for svg in *.svg
|
2020-04-21 14:30:53 +03:00
|
|
|
do
|
2020-04-21 14:50:26 +03:00
|
|
|
[[ -e "$svg" ]] || break
|
|
|
|
|
|
|
|
mv $svg $svg.opttmp
|
2020-04-21 14:30:53 +03:00
|
|
|
scour --create-groups \
|
|
|
|
--enable-id-stripping \
|
|
|
|
--enable-comment-stripping \
|
|
|
|
--shorten-ids \
|
|
|
|
--remove-metadata \
|
|
|
|
--strip-xml-prolog \
|
|
|
|
--no-line-breaks \
|
|
|
|
-i $svg.opttmp \
|
2020-04-21 14:33:11 +03:00
|
|
|
-o $svg
|
2020-04-21 14:50:26 +03:00
|
|
|
rm $svg.opttmp
|
2020-04-21 14:33:11 +03:00
|
|
|
done
|
2020-04-21 14:30:53 +03:00
|
|
|
|
|
|
|
# Check all subfolders
|
2020-04-21 14:32:11 +03:00
|
|
|
for dir in */
|
2020-04-21 14:30:53 +03:00
|
|
|
do
|
2020-04-21 14:50:26 +03:00
|
|
|
[[ -e "$dir" ]] || break
|
|
|
|
|
|
|
|
if [[ -d "$dir" ]]; then
|
2020-04-21 14:32:11 +03:00
|
|
|
recursive_optimize_images "$dir"
|
|
|
|
cd ..
|
|
|
|
fi
|
2020-04-21 14:33:11 +03:00
|
|
|
done
|
2013-04-13 12:01:13 +04:00
|
|
|
}
|
|
|
|
|
2020-04-21 14:50:26 +03:00
|
|
|
recursive_optimize_images "$CHECK_DIR"
|