From 9aa5533d1edcd713b5025c814b4a62694cbe7778 Mon Sep 17 00:00:00 2001 From: Jacob Roy Date: Thu, 4 May 2017 12:45:43 -0400 Subject: [PATCH] Version 1.0.0 Added a Help Menu, and updated the arguments, supporting Flags The Readme is also updated --- README.md | 40 ++++++++++++++----------------- guetzling | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 83 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 5143c5c..157921e 100644 --- a/README.md +++ b/README.md @@ -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Ă !*** @@ -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 \ No newline at end of file diff --git a/guetzling b/guetzling index cca5740..469495a 100755 --- a/guetzling +++ b/guetzling @@ -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 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')