From 29a4d8e4368fce5882e02798c2a2b0c33bb98b88 Mon Sep 17 00:00:00 2001 From: Nathan J Plummer Date: Mon, 1 May 2017 18:42:39 -0400 Subject: [PATCH] Add arguments for adjustable parameters and update README with usage examples. --- README.md | 72 ++++++++++++++++++++++++++++++++----------------------- guetzling | 48 ++++++++++++++++++++++++------------- 2 files changed, 73 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index c9614e1..5143c5c 100644 --- a/README.md +++ b/README.md @@ -11,33 +11,45 @@ By design, Guetzling will overwrite and/or delete your original files. If you w ## Usage 1. Simply `cd` to the parent directory of your choice, and `guetzling`. ***VoilĂ !*** -## Adjustable Options - -By opening the script in a text editor, you can adjust certain variables to change the output of Guetzling. - -### JPG - -Enable/Disable re-compression of JPG and JPEG files using Guetzling. - - #Recompress JPG Images - #Set to false to disable - JPG=true - -### PNG - -Enable/Disable the conversion of PNG to JPG using Guetzling. - - #Convert PNG Images - #Set to false to disable - #PNGS WILL BE DELETED AFTER CONVERSION - PNG=true - -### QUALITY - -Change Guetzling/Guetzli Quality Level. - - #Set Quality level - #Default = 95 - #Max = 100 - #Min = 84 - QUALITY=95 \ No newline at end of file +## Adjustable Parameters + +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 + +You can adjust these options using bash arguments: + +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 + +3. Compress JPGs + - Set to "false" and Guetzliing will ignore JPG/JPEG files, compressing only PNGS. + +4. Compress PNGs + - Set to "false" and Guetzling will ignore PNG files, compressing only JPGS + + 5. Delete PNG + - Set to "false" and Guetzling will keep the copy of any original PNGs in your folder + + +## Example Usage + + Replace all files at quality 95: + + ./guetzling + + Convert JPGs at 95, PNGs at 84, and keep your original PNG files: + + ./guetzling 95 84 true true false + + Convert only JPGs at Quality Level 97: + + ./guetzling 97 95 true false + \ No newline at end of file diff --git a/guetzling b/guetzling index 80e05f4..cca5740 100755 --- a/guetzling +++ b/guetzling @@ -1,19 +1,28 @@ #!/bin/bash +#Set Quality level for JPG recompression +#Default = 95 +#Max = 100 +#Min = 84 +QUALITY_JPG=${1:-95} + +#Set Quality level +#Default = 95 +#Max = 100 +#Min = 84 +QUALITY_PNG=${2:-95} + #Recompress JPG Images #Set to false to disable -JPG=true +JPG=${3:-true} #Convert PNG Images #Set to false to disable -#PNGS WILL BE DELETED AFTER CONVERSION -PNG=true +#PNGS WILL BE DELETED AFTER CONVERSION UNLESS OTHERWISE SPECIFIED +PNG=${4:-true} -#Set Quality level -#Default = 95 -#Max = 100 -#Min = 84 -QUALITY=95 +#Remove original PNGS after conversion to JPG +PNG_DELETE=${5:-true} IFS=$'\n'; FOLDER=$(pwd) @@ -23,8 +32,8 @@ if [ $JPG = true ]; for f in $(find "$FOLDER" -name '*.jpg') #for f in $1/*.jpg do - echo "Guetzling file - $f..." - guetzli --quality "$QUALITY" "$f" "$f" + echo "Guetzling file - $f at level '$QUALITY_JPG'..." + guetzli --quality "$QUALITY_JPG" "$f" "$f" echo "Done." done fi @@ -34,9 +43,9 @@ if [ $JPG = true ]; for f in $(find "$FOLDER" -name '*.jpeg') #for f in $1/*.jpeg do - echo "Guetzling file - $f..." - guetzli --quality "$QUALITY" "$f" "$f" - echo "Done." + echo "Guetzling file - $f at level '$QUALITY_JPG'..." + guetzli --quality "$QUALITY_JPG" "$f" "$f" + echo "Done." done fi @@ -45,9 +54,14 @@ if [ $PNG = true ]; for f in $(find "$FOLDER" -name '*.png') #for f in $1/*.png do - echo "Guetzling file - $f..." - guetzli --quality "$QUALITY" "$f" "${f%.png}.jpg" - rm "$f" - echo "Done." + 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