Allow shrinking a shrunk image. Add size to tag. Add defaults to usage. Tested successfully!

This commit is contained in:
Hyperling 2025-01-19 12:41:16 -07:00
parent 8fc05c43b5
commit 4a3ac3622f

View File

@ -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.