-
Notifications
You must be signed in to change notification settings - Fork 3
/
guetzling
executable file
·126 lines (108 loc) · 2.81 KB
/
guetzling
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
#Guetzling V 1.0.0
help() { echo -e "
$(basename $0), Version 1.0.0
Usage example: $(basename $0) -q 90 -j -f ~/photos/output
-q <84-100>, Sets the Quality, Default is 95
-j Recompress ONLY JPG (by default it will also recompress PNG)
-p Recompress ONLY PNG (by default it will also recompress JPG)
-k Keep the original PNG after conversion (by default it will not)
-f <folder> Speficify a folder of images to recompress, including subfolders (right now it's $(pwd))
" 1>&2; exit 1; }
#Set Quality level for JPG recompression
#Default = 95
#Max = 100
#Min = 84
QUALITY_JPG=95
#Set Quality level
#Default = 95
#Max = 100
#Min = 84
QUALITY_PNG=95
#Recompress JPG Images
#Set to false to disable
JPG=true
#Convert PNG Images
#Set to false to disable
#PNGS WILL BE DELETED AFTER CONVERSION UNLESS OTHERWISE SPECIFIED
PNG=true
#Remove original PNGS after conversion to JPG
PNG_DELETE=true
#Set the operating folder to pwd
FOLDER=$(pwd)
while getopts ":q:j:p:k:f:" o; do
case "${o}" in
q)
q=${OPTARG}
if ((q >= 84 || q <= 100))
then
QUALITY_JPG=${q}
echo "QUALITY_JPG = ${QUALITY_JPG}"
else
help
fi
;;
j)
j=${OPTARG}
PNG=false
echo "Recompressing JPG ONLY"
;;
p)
p=${OPTARG}
JPG=false
echo "Recompressing PNG ONLY"
;;
k)
k=${OPTARG}
PNG_DELETE=false
echo "Keeping PNG after compression"
;;
f)
f=${OPTARG}
FOLDER=${f}
echo "Working in folder ${f}, including subfolders"
;;
*)
help
;;
esac
done
shift $((OPTIND-1))
#if [ -z "${q}" ] || [ -z "${j}" ]; then
# help
#fi
IFS=$'\n';
if [ $JPG = true ];
then
for f in $(find "$FOLDER" -name '*.jpg')
#for f in $1/*.jpg
do
echo "Guetzling file - $f at level '$QUALITY_JPG'..."
guetzli --quality "$QUALITY_JPG" "$f" "$f"
echo "Done."
done
fi
if [ $JPG = true ];
then
for f in $(find "$FOLDER" -name '*.jpeg')
#for f in $1/*.jpeg
do
echo "Guetzling file - $f at level '$QUALITY_JPG'..."
guetzli --quality "$QUALITY_JPG" "$f" "$f"
echo "Done."
done
fi
if [ $PNG = true ];
then
for f in $(find "$FOLDER" -name '*.png')
#for f in $1/*.png
do
echo "Guetzling file - $f at level '$QUALITY_PNG' ..."
guetzli --quality "$QUALITY_PNG" "$f" "${f%.png}.jpg"
if [ $PNG_DELETE = true ];
then
rm "$f"
fi
echo "Done."
done
fi