From 4a3ac3622f83d7017af4fdee75d44980fcd69198 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Sun, 19 Jan 2025 12:41:16 -0700 Subject: [PATCH] Allow shrinking a shrunk image. Add size to tag. Add defaults to usage. Tested successfully! --- files/scripts/compress_image.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/files/scripts/compress_image.sh b/files/scripts/compress_image.sh index 9b647ac..0bc32cc 100755 --- a/files/scripts/compress_image.sh +++ b/files/scripts/compress_image.sh @@ -34,9 +34,12 @@ function usage() { Parameters: -s SIZE : Integer for the maximum length of either image dimension. + Default size is 2000. -l LOCATION : The specific image or folder which needs images shrunk. + Default location is the current directory. -r : Recursively shrink images based on the location passed. -f : Force the image to be shrunk even if a file already exists for it. + -F : FORCE the image to be shrunk even if the file is already shrunk. -d : Delete the original image if the compressed image is smaller. -c : Clean the filename of underscores, dashes, 'IMG', etc. -A : Resursively Force, Delete, and Clean. @@ -48,12 +51,13 @@ function usage() { ## Parameters ## -while getopts ":s:l:rfdcAhx" opt; do +while getopts ":s:l:rfFdcAhx" opt; do case $opt in s) in_size="$OPTARG" && size="$in_size" ;; l) location="$OPTARG" ;; r) recurse="Y" && search="find" ;; f) force="Y" ;; + F) super_force="Y" ;; d) delete="Y" ;; c) clean="Y" ;; A) recurse="Y" && search="find" && force="Y" && delete="Y" && clean="Y" ;; @@ -90,8 +94,8 @@ $search "$location" | sort | while read image; do # Avoid processing directories no matter the name. [ -d "$image" ] && continue - # Avoid processing files previously shrunk. - [[ "$image" == *"$tag"* ]] && continue + # Avoid processing files previously shrunk, unless we are FORCEing. + [[ "$image" == *"$tag"* && -z "$super_force" ]] && continue echo -e "\n$image" @@ -107,7 +111,7 @@ $search "$location" | sort | while read image; do fi - new_image="${image//.$extension/}.$tag-$date_YYYYMMDD.$extension" + new_image="${image//.$extension/}.$tag-$date_YYYYMMDD-$size.$extension" ## Clean Filename ## # Prevent directory from having its name cleaned too.