-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathimageshrink
executable file
·70 lines (60 loc) · 1.07 KB
/
imageshrink
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
#
# imageshrink
#
# Shrink the specified image(s)
#
# Author: Emanuel Duss
#
set -o errexit
set -o nounset
set -o pipefail
print_help(){
cat << EOI
Usage: imageshrink [files ...]
EOI
}
check_dependencies(){
FAIL=0
for tool in $@
do
if ! hash "$tool" &> /dev/null
then
echo "The tool $tool does not exist."
FAIL=1
fi
done
if [[ "$FAIL" == 1 ]]
then
exit 1
fi
}
main(){
check_dependencies convert
FOLDER="small"
QUALITY="75"
SIZE="1280x1280"
SIZE="2048x2048"
if [[ ! -d "$FOLDER" ]]
then
mkdir "$FOLDER"
fi
TOTAL="$(echo $@ | wc -w)"
COUNT=0
for photo in $@
do
COUNT=$((COUNT + 1))
echo -ne "\r\033[KProcessing $photo: $COUNT/$TOTAL ($(( 100 * $COUNT / $TOTAL))%)"
destination="$FOLDER/$photo"
if [[ ! -f "$destination" && -f "$photo" && ! -d "$photo" ]]
then
if ! convert -resize "$SIZE" -quality "$QUALITY" "$photo" "$destination"
then
echo "Error while processing $photo."
fi
fi
done
echo
}
trap "echo; exit 1" SIGINT SIGTERM
main "$@"