Skip to content

Commit 9aa5533

Browse files
committed
Version 1.0.0
Added a Help Menu, and updated the arguments, supporting Flags The Readme is also updated
1 parent dfaa83e commit 9aa5533

File tree

2 files changed

+83
-28
lines changed

2 files changed

+83
-28
lines changed

README.md

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ By design, Guetzling will overwrite and/or delete your original files. If you w
66

77
## Install Guetzli
88
1. Install [Guetzli](https://github.com/google/guetzli), via the directions provided at the link.
9-
2. Copy Guetzling, copy it to `/usr/bin`.
9+
2. Copy Guetzling to `/usr/bin`.
1010

1111
## Usage
1212
1. Simply `cd` to the parent directory of your choice, and `guetzling`. ***Voilà!***
@@ -16,40 +16,36 @@ By design, Guetzling will overwrite and/or delete your original files. If you w
1616
By Default, Guetzling uses the following options:
1717

1818
- JPGs are re-compressed and overwritten
19-
- PNGs are converted to JPG and the originals are deleted
20-
- Quality Level is for Guetzli is set to 95
19+
- PNGs are converted to JPG, re-compressed, and the originals are deleted
20+
- Quality Level is set to 95
2121

22-
You can adjust these options using bash arguments:
22+
You can adjust these options using flags:
2323

24-
1. Quality for JPG re-compression.
25-
- Requires a value between 84 and 100 for Guetzli is designed to fail
26-
- Default value is the same as Guetzli: 95
27-
28-
2. Quality for PNG conversion.
29-
- Requires a value between 84 and 100 for Guetzli is designed to fail
30-
- Default value is the same as Guetzli: 95
24+
-q Quality for JPG or PNG re-compression.
25+
- Requires a value between 84 and 100.
26+
- Default value is the same as Guetzli: 95.
3127

32-
3. Compress JPGs
33-
- Set to "false" and Guetzliing will ignore JPG/JPEG files, compressing only PNGS.
28+
-j Compress JPGs ONLY
29+
- Use this flag and Guetzling will ignore PNGs files, compressing only JPGs.
3430

35-
4. Compress PNGs
36-
- Set to "false" and Guetzling will ignore PNG files, compressing only JPGS
31+
-p Compress PNGs ONLY
32+
- Use this flag and Guetzling will ignore JPGs files, compressing only PNGs.
3733

38-
5. Delete PNG
39-
- Set to "false" and Guetzling will keep the copy of any original PNGs in your folder
34+
-k Keep PNG
35+
- Use this flag and Guetzling will keep original PNGs files, and output compressed JPGs.
4036

4137

4238
## Example Usage
4339

44-
Replace all files at quality 95:
40+
Replace all files at quality 95 :
4541

4642
./guetzling
4743

48-
Convert JPGs at 95, PNGs at 84, and keep your original PNG files:
44+
Convert PNGs at 84, and keep your original PNG files :
4945

50-
./guetzling 95 84 true true false
46+
./guetzling -q 84 -p -k
5147

52-
Convert only JPGs at Quality Level 97:
48+
Convert only JPGs at Quality 97 in /Users/test/photos/output :
5349

54-
./guetzling 97 95 true false
50+
./guetzling -q 97 -j -f /Users/test/photos/output
5551

guetzling

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,91 @@
11
#!/bin/bash
2+
#Guetzling V 1.0.0
3+
help() { echo -e "
4+
$(basename $0), Version 1.0.0
5+
6+
Usage example: $(basename $0) -q 90 -j -f ~/photos/output
7+
8+
-q <84-100>, Sets the Quality, Default is 95
9+
-j Recompress ONLY JPG (by default it will also recompress PNG)
10+
-p Recompress ONLY PNG (by default it will also recompress JPG)
11+
-k Keep the original PNG after conversion (by default it will not)
12+
-f <folder> Speficify a folder of images to recompress, including subfolders (right now it's $(pwd))
13+
" 1>&2; exit 1; }
214

315
#Set Quality level for JPG recompression
416
#Default = 95
517
#Max = 100
618
#Min = 84
7-
QUALITY_JPG=${1:-95}
19+
QUALITY_JPG=95
820

921
#Set Quality level
1022
#Default = 95
1123
#Max = 100
1224
#Min = 84
13-
QUALITY_PNG=${2:-95}
25+
QUALITY_PNG=95
1426

1527
#Recompress JPG Images
1628
#Set to false to disable
17-
JPG=${3:-true}
29+
JPG=true
1830

1931
#Convert PNG Images
2032
#Set to false to disable
2133
#PNGS WILL BE DELETED AFTER CONVERSION UNLESS OTHERWISE SPECIFIED
22-
PNG=${4:-true}
34+
PNG=true
2335

2436
#Remove original PNGS after conversion to JPG
25-
PNG_DELETE=${5:-true}
37+
PNG_DELETE=true
2638

27-
IFS=$'\n';
39+
#Set the operating folder to pwd
2840
FOLDER=$(pwd)
2941

42+
while getopts ":q:j:p:k:f:" o; do
43+
case "${o}" in
44+
q)
45+
q=${OPTARG}
46+
if ((q >= 84 || q <= 100))
47+
then
48+
QUALITY_JPG=${q}
49+
echo "QUALITY_JPG = ${QUALITY_JPG}"
50+
else
51+
help
52+
fi
53+
;;
54+
j)
55+
j=${OPTARG}
56+
PNG=false
57+
echo "Recompressing JPG ONLY"
58+
;;
59+
p)
60+
p=${OPTARG}
61+
JPG=false
62+
echo "Recompressing PNG ONLY"
63+
;;
64+
k)
65+
k=${OPTARG}
66+
PNG_DELETE=false
67+
echo "Keeping PNG after compression"
68+
;;
69+
f)
70+
f=${OPTARG}
71+
FOLDER=${f}
72+
echo "Working in folder ${f}, including subfolders"
73+
;;
74+
*)
75+
help
76+
;;
77+
esac
78+
done
79+
shift $((OPTIND-1))
80+
81+
#if [ -z "${q}" ] || [ -z "${j}" ]; then
82+
# help
83+
#fi
84+
85+
86+
87+
IFS=$'\n';
88+
3089
if [ $JPG = true ];
3190
then
3291
for f in $(find "$FOLDER" -name '*.jpg')

0 commit comments

Comments
 (0)