File tree Expand file tree Collapse file tree 1 file changed +66
-0
lines changed Expand file tree Collapse file tree 1 file changed +66
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments