From 76c81548bfd0fc619d89384466e7b7b121395232 Mon Sep 17 00:00:00 2001 From: poprhythm Date: Wed, 26 Nov 2025 19:57:06 -0500 Subject: [PATCH] Initial commit --- images_resize.sh | 14 ++++++++ images_resize_recursive.sh | 9 +++++ rar2zip.sh | 53 +++++++++++++++++++++++++++++ rar2zip_images.sh | 1 + rar2zip_incomplete.sh | 1 + zip_images_recursive.sh | 37 ++++++++++++++++++++ zip_images_resize.sh | 62 ++++++++++++++++++++++++++++++++++ zip_images_resize_recursive.sh | 5 +++ 8 files changed, 182 insertions(+) create mode 100755 images_resize.sh create mode 100755 images_resize_recursive.sh create mode 100755 rar2zip.sh create mode 100755 rar2zip_images.sh create mode 100755 rar2zip_incomplete.sh create mode 100755 zip_images_recursive.sh create mode 100755 zip_images_resize.sh create mode 100755 zip_images_resize_recursive.sh diff --git a/images_resize.sh b/images_resize.sh new file mode 100755 index 0000000..e3991f7 --- /dev/null +++ b/images_resize.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# +# images_resize Resizing large JPGs in current directory +# Based on: https://shkspr.mobi/blog/2016/12/converting-rar-to-zip-in-linux/ +# +# Usage: xxx.sh + +echo "Resizing large JPGs in $(pwd)" + +for f in $(find . -regextype posix-egrep -regex ".*\.(jpg|JPG|JPEG|jpeg)$") +#echo "Resizing $(f)" +#do mogrify -resize 2800000@@\> -sampling-factor 4:2:0 -strip -quality 85% -colorspace RGB $f +do ~/Applications/magick "$f" -resize 8000000@@\> -sampling-factor 4:2:0 -strip -quality 85% "$f" +done diff --git a/images_resize_recursive.sh b/images_resize_recursive.sh new file mode 100755 index 0000000..9519874 --- /dev/null +++ b/images_resize_recursive.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +for f in ./** +do + pushd "$f" + ~/images_resize.sh + popd +done + diff --git a/rar2zip.sh b/rar2zip.sh new file mode 100755 index 0000000..c33f436 --- /dev/null +++ b/rar2zip.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# +# rar2zip conversion script +# Based on: https://shkspr.mobi/blog/2016/12/converting-rar-to-zip-in-linux/ +# +# Usage: rar2zip.sh file [file ...] + +echo "Converting RARs to ZIPs" + +# Use RAM disk for temporary files. +WORKDIR="/dev/shm/" + +for INFILE in "$@"; do + # Absolute path to old file + OLDFILE=`realpath "${INFILE}"` + + # Get the file name without the extension + BASENAME=`basename "${OLDFILE%.*}"` + + # Path for the file. The ".zip" file will be written there. + DIRNAME=`dirname "$OLDFILE"` + + # Name of the .zip file + NEWNAME="${DIRNAME}/$BASENAME.zip" + + if [ ! -e "${NEWNAME}" ]; then + # Set name for the temp dir. This directory will be created under WORKDIR + TEMPDIR=`mktemp -p "$WORKDIR" -d` + + # Create a temporary folder for unRARed files + echo "Extracting $OLDFILE" + + rar x "$OLDFILE" "${TEMPDIR}/" + + # Zip the files with maximum compression + 7z a -tzip -mx=9 "$NEWNAME" "${TEMPDIR}/*" + # Alternative. MUCH SLOWER, but better compression + # 7z a -mm=Deflate -mfb=258 -mpass=15 -r "$NEWNAME" * + + # Preserve file modification time + touch -r "$OLDFILE" "$NEWNAME" + + # Delete the temporary directory + rm -r "$TEMPDIR" + + # OPTIONAL. Safe-remove the old file + #gio trash "$OLDFILE" + else + echo "${NEWNAME}: File exists!" + fi +done + +echo "Conversion Done" diff --git a/rar2zip_images.sh b/rar2zip_images.sh new file mode 100755 index 0000000..f70e3d5 --- /dev/null +++ b/rar2zip_images.sh @@ -0,0 +1 @@ +find /media/rewt/media/images/ -name '*.rar' -exec ~/rar2zip.sh '{}' \; diff --git a/rar2zip_incomplete.sh b/rar2zip_incomplete.sh new file mode 100755 index 0000000..dd901d3 --- /dev/null +++ b/rar2zip_incomplete.sh @@ -0,0 +1 @@ +find /media/rewt/media/incomplete/ -name '*.rar' -exec ~/rar2zip.sh '{}' \; diff --git a/zip_images_recursive.sh b/zip_images_recursive.sh new file mode 100755 index 0000000..072dd67 --- /dev/null +++ b/zip_images_recursive.sh @@ -0,0 +1,37 @@ +#!/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 + + +for subd in *; do + if [ -d "${subd}" ]; then + pushd "${subd}" + ~/zip_images_recursive.sh "${directoryTree}" + popd + fi +done diff --git a/zip_images_resize.sh b/zip_images_resize.sh new file mode 100755 index 0000000..e7ed865 --- /dev/null +++ b/zip_images_resize.sh @@ -0,0 +1,62 @@ +#!/bin/bash +# +# zip_images_resize Resizing large JPGs in ZIPs +# Based on: https://shkspr.mobi/blog/2016/12/converting-rar-to-zip-in-linux/ +# +# Usage: xxx.sh file [file ...] + +echo "Resizing large JPGs in ZIPs" + +# Use RAM disk for temporary files. +WORKDIR="/dev/shm/" + +for INFILE in "$@"; do + # Absolute path to old file + #OLDFILE=`realpath "${INFILE}"` + OUTFILE="${INFILE%.zip}-compress.zip" + + if [ ! -e "${OUTFILE}" ]; then + rm "${OUTFILE}" + fi + # Set name for the temp dir. This directory will be created under WORKDIR + TEMPDIR=`mktemp -p "$WORKDIR" -d` + + # Create a temporary folder for unRARed files + echo "Extracting $INFILE" + + # extract files from zip + unzip "$INFILE" -d "$TEMPDIR" # -j to junk directories + + # resize + #convert '${TEMPDIR}/*.jpg' -set filename:fn '%[basename]' -resize 2800000@@\> -sampling-factor 4:2:0 -strip -quality 85% -colorspace RGB '%[filename:fn].jpg' + + pushd "$TEMPDIR" + ~/images_resize.sh + popd + + # Zip the files with no compression + 7z a -tzip -mx=0 "$OUTFILE" "${TEMPDIR}/*" + + if [ $? -ne 0 ]; then + echo Exiting + exit 1 + fi + + + # Alternative. MUCH SLOWER, but better compression + # 7z a -mm=Deflate -mfb=258 -mpass=15 -r "$NEWNAME" * + + # Preserve file modification time + touch -r "$INFILE" "$OUTFILE" + rm "$INFILE" + mv "$OUTFILE" "$INFILE" + + # Delete the temporary directory + rm -r "$TEMPDIR" + + # OPTIONAL. Safe-remove the old file + #gio trash "$OLDFILE" + +done + +echo "Conversion Done" diff --git a/zip_images_resize_recursive.sh b/zip_images_resize_recursive.sh new file mode 100755 index 0000000..f2cc0ca --- /dev/null +++ b/zip_images_resize_recursive.sh @@ -0,0 +1,5 @@ +#!/bin/bash +IFS=$'\n'; set -f +find . -iname *.zip -exec ~/zip_images_resize.sh '{}' \; +unset IFS; set +f +