Files
image_processing/zip_images_recursive.sh
T
2025-11-27 04:22:46 +00:00

38 lines
854 B
Bash
Executable File

#!/bin/bash
#
# zip_images_recursive Resizing large JPGs in current directory
# Based on: https://shkspr.mobi/blog/2016/12/converting-rar-to-zip-in-linux/
#
# Usage: xxx.sh
pushd () {
command pushd "$@" > /dev/null
}
popd () {
command popd "$@" > /dev/null
}
cwd=${PWD##*/}
directoryTree="${cwd}"
if [ "$#" -ne 0 ]; then
directoryTree="${1} - ${directoryTree}"
fi
jpgs=$(find . -maxdepth 1 -regextype posix-egrep -regex ".*\.(jpg|JPG|JPEG|jpeg)$")
if [ -n "$jpgs" ]; then
echo "Zipping JPGs in ${directoryTree}"
7z a -tzip -mx=0 "$directoryTree.zip" "*.jpg" -i!*.jpeg -i!*.JPG -i!*.JPEG
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
find . -mindepth 1 -maxdepth 1 -type d -print0 | while IFS= read -r -d '' subd; do
pushd "${subd}"
"$SCRIPT_DIR/zip_images_recursive.sh" "${directoryTree}"
popd
done