nextcloud/build/image-optimization.sh

65 lines
1005 B
Bash
Raw Normal View History

2015-09-27 14:03:31 +03:00
#!/usr/bin/env bash
2013-04-13 12:01:13 +04:00
CHECK_DIR='../'
if [[ -d "$1" ]]; then
CHECK_DIR=$1
fi
2013-04-13 12:01:13 +04:00
function recursive_optimize_images() {
cd "$1" || return
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
# Optimize all JPGs
for jpg in *.jpg
do
[[ -e "$jpg" ]] || break
jpegoptim --strip-all "$jpg"
done
# Optimize all SVGs
for svg in *.svg
do
[[ -e "$svg" ]] || break
mv $svg $svg.opttmp
scour --create-groups \
--enable-id-stripping \
--enable-comment-stripping \
--shorten-ids \
--remove-metadata \
--strip-xml-prolog \
--no-line-breaks \
-i $svg.opttmp \
-o $svg
rm $svg.opttmp
done
# Check all subfolders
for dir in */
do
[[ -e "$dir" ]] || break
if [[ -d "$dir" ]]; then
recursive_optimize_images "$dir"
cd ..
fi
done
2013-04-13 12:01:13 +04:00
}
recursive_optimize_images "$CHECK_DIR"