Files
image_processing/zip_images_recursive.sh
T
2025-11-27 02:33:17 +00:00

36 lines
782 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
find . -mindepth 1 -maxdepth 1 -type d -print0 | while IFS= read -r -d '' subd; do
pushd "${subd}"
~/zip_images_recursive.sh "${directoryTree}"
popd
done