Skip to content

Commit 3e4acaa

Browse files
committed
fix: filename
1 parent f709a3b commit 3e4acaa

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

scripts/optimize-png.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
# Derived from http://www.clock.co.uk/blog/optimise-your-pngs-from-the-terminal-in-osx
3+
# NOTE: This script will optimize the input png file and rewrites on the same file.
4+
# Requires:
5+
# optipng
6+
# On OSX:
7+
# brew install optipng
8+
9+
get_script_dir () {
10+
SOURCE="${BASH_SOURCE[0]}"
11+
# While $SOURCE is a symlink, resolve it
12+
while [ -h "$SOURCE" ]; do
13+
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
14+
SOURCE="$( readlink "$SOURCE" )"
15+
# If $SOURCE was a relative symlink (so no "/" as prefix,
16+
# need to resolve it relative to the symlink base directory
17+
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
18+
done
19+
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
20+
echo "$DIR"
21+
}
22+
23+
THIS_SCRIPT_DIR=$(get_script_dir)
24+
25+
#
26+
# Print usage
27+
#
28+
usage () {
29+
echo "optimize-png.sh [-o{2-7}] -i=image.png"
30+
exit 1
31+
}
32+
33+
#
34+
# Check arguments passed to the script
35+
#
36+
# Args:
37+
# $@: all arguments passed to the script
38+
#
39+
check_args () {
40+
if [ $# -eq 0 ]; then usage; fi
41+
# set default
42+
OPTLEVEL="2"
43+
for i in "$@"
44+
do
45+
echo $i
46+
case $i in
47+
-i=*|--input=*)
48+
INPUT="${i#*=}"
49+
shift
50+
;;
51+
-o=*|--optlevel=*)
52+
OPTLEVEL="${i#*=}"
53+
shift
54+
;;
55+
*)
56+
usage
57+
;;
58+
esac
59+
done
60+
}
61+
62+
#
63+
check_args $@
64+
65+
# Optimize the input png
66+
optipng -o${OPTLEVEL} $INPUT

0 commit comments

Comments
 (0)