Skip to content

Commit

Permalink
Version 1.0.0
Browse files Browse the repository at this point in the history
Added a Help Menu, and updated the arguments, supporting Flags

The Readme is also updated
  • Loading branch information
lejacobroy committed May 4, 2017
1 parent dfaa83e commit 9aa5533
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 28 deletions.
40 changes: 18 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ By design, Guetzling will overwrite and/or delete your original files. If you w

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

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

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

You can adjust these options using bash arguments:
You can adjust these options using flags:

1. Quality for JPG re-compression.
- Requires a value between 84 and 100 for Guetzli is designed to fail
- Default value is the same as Guetzli: 95

2. Quality for PNG conversion.
- Requires a value between 84 and 100 for Guetzli is designed to fail
- Default value is the same as Guetzli: 95
-q Quality for JPG or PNG re-compression.
- Requires a value between 84 and 100.
- Default value is the same as Guetzli: 95.

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

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

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


## Example Usage

Replace all files at quality 95:
Replace all files at quality 95 :

./guetzling

Convert JPGs at 95, PNGs at 84, and keep your original PNG files:
Convert PNGs at 84, and keep your original PNG files :

./guetzling 95 84 true true false
./guetzling -q 84 -p -k

Convert only JPGs at Quality Level 97:
Convert only JPGs at Quality 97 in /Users/test/photos/output :

./guetzling 97 95 true false
./guetzling -q 97 -j -f /Users/test/photos/output

71 changes: 65 additions & 6 deletions guetzling
Original file line number Diff line number Diff line change
@@ -1,32 +1,91 @@
#!/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=${1:-95}
QUALITY_JPG=95

#Set Quality level
#Default = 95
#Max = 100
#Min = 84
QUALITY_PNG=${2:-95}
QUALITY_PNG=95

#Recompress JPG Images
#Set to false to disable
JPG=${3:-true}
JPG=true

#Convert PNG Images
#Set to false to disable
#PNGS WILL BE DELETED AFTER CONVERSION UNLESS OTHERWISE SPECIFIED
PNG=${4:-true}
PNG=true

#Remove original PNGS after conversion to JPG
PNG_DELETE=${5:-true}
PNG_DELETE=true

IFS=$'\n';
#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')
Expand Down

0 comments on commit 9aa5533

Please sign in to comment.