-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptimweb.sh
More file actions
50 lines (44 loc) · 1.1 KB
/
optimweb.sh
File metadata and controls
50 lines (44 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh
selfpath=`realpath $0`
selfdir=`dirname $selfpath`
selffile=`basename $0`
selfname=${selffile%.*}
source "$selfdir/functions.sh"
recursively="false"
keep_original="false"
while getopts "hrk" arg; do
case $arg in
h) # Display help.
usage $selfname
exit 0
;;
r) # Keep original image
recursively="true"
shift # It is supposed to be the first / second argument
;;
k) # Keep original image
keep_original="true"
shift # It is supposed to be the first / second argument
;;
esac
done
printf "Searching images...\n"
if [ $# -eq 0 ] # Recursively in the working directory
then
get_all_images . $recursively # Return paths in $retval
optimize_images $retval $keep_original
else
image_paths=""
for input in $*
do # Multiple arguments or pattern
if is_image $input
then
image_paths="$image_paths$input\n"
else
check_dir_exists $input
get_all_images $input $recursively # Return paths in $retval
image_paths="$image_paths$retval\n"
fi
done
optimize_images $image_paths $keep_original
fi