Add a parameter to image compressing which does not use a big fancy tag.

This commit is contained in:
2025-12-08 15:15:11 -07:00
parent ea3ce8d023
commit b8fa688e52

View File

@@ -15,6 +15,7 @@ size=2000
# Strings
tag="shrunk"
use_tag="Y"
date_YYYYMMDD="`date "+%Y%m%d"`"
location="."
search="ls"
@@ -28,7 +29,7 @@ function usage() {
# Parameters:
# 1) The exit status to use.
status=$1
echo "Usage: $PROG [-s SIZE] [-l LOCATION] [-A | [-r] [-f] [-d] [-c] [-e | -t] [-h] [-x]" >&2
echo "Usage: $PROG [-s SIZE] [-l LOCATION] [-A | [-r] [-f] [-d] [-c] [-e | -t] [-h] [-x] [-n]" >&2
cat <<- EOF
Compress JPG or PNG image(s). Can handle folders and work recursively.
@@ -46,13 +47,14 @@ function usage() {
-A : Resursively Force, Delete, and Clean.
-h : Display this usage text.
-x : Enable BASH debugging.
-n : No file extension.
EOF
exit $status
}
## Parameters ##
while getopts ":s:l:rfFdcetAhx" opt; do
while getopts ":s:l:rfFdcetAhxn" opt; do
case $opt in
s) in_size="$OPTARG" && size="$in_size" ;;
l) location="$OPTARG" ;;
@@ -66,6 +68,7 @@ while getopts ":s:l:rfFdcetAhx" opt; do
A) recurse="Y" && search="find" && force="Y" && delete="Y" ;;
h) usage 0 ;;
x) set -x ;;
n) use_tag="N" ;;
*) echo "ERROR: Option $OPTARG not recognized." >&2 && usage 1 ;;
esac
done
@@ -114,6 +117,12 @@ $search "$location" | sort | while read image; do
fi
new_image="${image//.$extension/}.$tag-$date_YYYYMMDD.$size.$extension"
if [[ "$use_tag" == "N" ]]; then
new_image="$image"
new_image="${new_image//.$extension/}"
new_image="${new_image//.$tag/}"
new_image="$new_image.$tag.$extension"
fi
## Clean Filename ##
# Prevent directory from having its name cleaned too.
@@ -154,7 +163,7 @@ $search "$location" | sort | while read image; do
fi
# Skip if a compressed image was already created today.
if [[ -e "$new_image" || -e $new_image_clean ]]; then
if [[ (-e "$new_image" || -e $new_image_clean) && $use_tag == "Y" ]]; then
echo " SKIP: Image has already been shrunk previously, moving on."
continue
fi