This commit is contained in:
2025-11-27 02:33:17 +00:00
parent 76c81548bf
commit c4528f1319
8 changed files with 79 additions and 36 deletions
+2 -2
View File
@@ -7,8 +7,8 @@
echo "Resizing large JPGs in $(pwd)" echo "Resizing large JPGs in $(pwd)"
for f in $(find . -regextype posix-egrep -regex ".*\.(jpg|JPG|JPEG|jpeg)$") find . -regextype posix-egrep -regex ".*\.(jpg|JPG|JPEG|jpeg)$" -print0 | while IFS= read -r -d '' f
#echo "Resizing $(f)" #echo "Resizing $(f)"
#do mogrify -resize 2800000@@\> -sampling-factor 4:2:0 -strip -quality 85% -colorspace RGB $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" do ~/Applications/magick "$f" -resize 8000000@@\> -sampling-factor 4:2:0 -strip -quality 85% "$f"
done done
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
for f in ./** find . -mindepth 1 -type d -print0 | while IFS= read -r -d '' f
do do
pushd "$f" pushd "$f"
~/images_resize.sh ~/images_resize.sh
+31 -8
View File
@@ -10,30 +10,52 @@ echo "Converting RARs to ZIPs"
# Use RAM disk for temporary files. # Use RAM disk for temporary files.
WORKDIR="/dev/shm/" WORKDIR="/dev/shm/"
# Cleanup function
cleanup_temp() {
if [ -n "$TEMPDIR" ] && [ -d "$TEMPDIR" ]; then
rm -r "$TEMPDIR"
fi
}
for INFILE in "$@"; do for INFILE in "$@"; do
# Absolute path to old file # Absolute path to old file
OLDFILE=`realpath "${INFILE}"` OLDFILE=$(realpath "${INFILE}")
# Get the file name without the extension # Get the file name without the extension
BASENAME=`basename "${OLDFILE%.*}"` BASENAME=$(basename "${OLDFILE%.*}")
# Path for the file. The ".zip" file will be written there. # Path for the file. The ".zip" file will be written there.
DIRNAME=`dirname "$OLDFILE"` DIRNAME=$(dirname "$OLDFILE")
# Name of the .zip file # Name of the .zip file
NEWNAME="${DIRNAME}/$BASENAME.zip" NEWNAME="${DIRNAME}/$BASENAME.zip"
if [ ! -e "${NEWNAME}" ]; then if [ ! -e "${NEWNAME}" ]; then
# Set name for the temp dir. This directory will be created under WORKDIR # Set name for the temp dir. This directory will be created under WORKDIR
TEMPDIR=`mktemp -p "$WORKDIR" -d` TEMPDIR=$(mktemp -p "$WORKDIR" -d)
# Set up cleanup trap
trap cleanup_temp EXIT INT TERM
# Create a temporary folder for unRARed files # Create a temporary folder for unRARed files
echo "Extracting $OLDFILE" echo "Extracting $OLDFILE"
rar x "$OLDFILE" "${TEMPDIR}/" if ! rar x "$OLDFILE" "${TEMPDIR}/"; then
echo "Error: Failed to extract $OLDFILE"
cleanup_temp
continue
fi
# Zip the files with maximum compression # Zip the files with maximum compression
7z a -tzip -mx=9 "$NEWNAME" "${TEMPDIR}/*" pushd "$TEMPDIR" > /dev/null
if ! 7z a -tzip -mx=9 "$NEWNAME" ./*; then
echo "Error: Failed to create ZIP for $BASENAME"
popd > /dev/null
cleanup_temp
continue
fi
popd > /dev/null
# Alternative. MUCH SLOWER, but better compression # Alternative. MUCH SLOWER, but better compression
# 7z a -mm=Deflate -mfb=258 -mpass=15 -r "$NEWNAME" * # 7z a -mm=Deflate -mfb=258 -mpass=15 -r "$NEWNAME" *
@@ -41,7 +63,8 @@ for INFILE in "$@"; do
touch -r "$OLDFILE" "$NEWNAME" touch -r "$OLDFILE" "$NEWNAME"
# Delete the temporary directory # Delete the temporary directory
rm -r "$TEMPDIR" cleanup_temp
trap - EXIT INT TERM
# OPTIONAL. Safe-remove the old file # OPTIONAL. Safe-remove the old file
#gio trash "$OLDFILE" #gio trash "$OLDFILE"
+1
View File
@@ -1 +1,2 @@
#!/bin/bash
find /media/rewt/media/images/ -name '*.rar' -exec ~/rar2zip.sh '{}' \; find /media/rewt/media/images/ -name '*.rar' -exec ~/rar2zip.sh '{}' \;
+1
View File
@@ -1 +1,2 @@
#!/bin/bash
find /media/rewt/media/incomplete/ -name '*.rar' -exec ~/rar2zip.sh '{}' \; find /media/rewt/media/incomplete/ -name '*.rar' -exec ~/rar2zip.sh '{}' \;
+4 -6
View File
@@ -28,10 +28,8 @@ if [ -n "$jpgs" ]; then
fi fi
for subd in *; do find . -mindepth 1 -maxdepth 1 -type d -print0 | while IFS= read -r -d '' subd; do
if [ -d "${subd}" ]; then pushd "${subd}"
pushd "${subd}" ~/zip_images_recursive.sh "${directoryTree}"
~/zip_images_recursive.sh "${directoryTree}" popd
popd
fi
done done
+38 -16
View File
@@ -10,38 +10,59 @@ echo "Resizing large JPGs in ZIPs"
# Use RAM disk for temporary files. # Use RAM disk for temporary files.
WORKDIR="/dev/shm/" WORKDIR="/dev/shm/"
# Cleanup function
cleanup_temp() {
if [ -n "$TEMPDIR" ] && [ -d "$TEMPDIR" ]; then
rm -r "$TEMPDIR"
fi
}
for INFILE in "$@"; do for INFILE in "$@"; do
# Absolute path to old file # Absolute path to old file
#OLDFILE=`realpath "${INFILE}"` #OLDFILE=$(realpath "${INFILE}")
OUTFILE="${INFILE%.zip}-compress.zip" OUTFILE="${INFILE%.zip}-compress.zip"
if [ ! -e "${OUTFILE}" ]; then # Remove output file if it already exists
if [ -e "${OUTFILE}" ]; then
rm "${OUTFILE}" rm "${OUTFILE}"
fi 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 # Set name for the temp dir. This directory will be created under WORKDIR
TEMPDIR=$(mktemp -p "$WORKDIR" -d)
# Set up cleanup trap
trap cleanup_temp EXIT INT TERM
# Create a temporary folder for unzipped files
echo "Extracting $INFILE" echo "Extracting $INFILE"
# extract files from zip # extract files from zip
unzip "$INFILE" -d "$TEMPDIR" # -j to junk directories if ! unzip "$INFILE" -d "$TEMPDIR"; then
echo "Error: Failed to extract $INFILE"
cleanup_temp
continue
fi
# resize # resize
#convert '${TEMPDIR}/*.jpg' -set filename:fn '%[basename]' -resize 2800000@@\> -sampling-factor 4:2:0 -strip -quality 85% -colorspace RGB '%[filename:fn].jpg' #convert '${TEMPDIR}/*.jpg' -set filename:fn '%[basename]' -resize 2800000@@\> -sampling-factor 4:2:0 -strip -quality 85% -colorspace RGB '%[filename:fn].jpg'
pushd "$TEMPDIR" if ! pushd "$TEMPDIR" > /dev/null; then
echo "Error: Failed to change to temp directory"
cleanup_temp
continue
fi
~/images_resize.sh ~/images_resize.sh
popd popd > /dev/null
# Zip the files with no compression # Zip the files with no compression
7z a -tzip -mx=0 "$OUTFILE" "${TEMPDIR}/*" pushd "$TEMPDIR" > /dev/null
if ! 7z a -tzip -mx=0 "$OUTFILE" ./*; then
if [ $? -ne 0 ]; then echo "Error: Failed to create ZIP"
echo Exiting popd > /dev/null
exit 1 cleanup_temp
continue
fi fi
popd > /dev/null
# Alternative. MUCH SLOWER, but better compression # Alternative. MUCH SLOWER, but better compression
# 7z a -mm=Deflate -mfb=258 -mpass=15 -r "$NEWNAME" * # 7z a -mm=Deflate -mfb=258 -mpass=15 -r "$NEWNAME" *
@@ -52,7 +73,8 @@ for INFILE in "$@"; do
mv "$OUTFILE" "$INFILE" mv "$OUTFILE" "$INFILE"
# Delete the temporary directory # Delete the temporary directory
rm -r "$TEMPDIR" cleanup_temp
trap - EXIT INT TERM
# OPTIONAL. Safe-remove the old file # OPTIONAL. Safe-remove the old file
#gio trash "$OLDFILE" #gio trash "$OLDFILE"
+1 -3
View File
@@ -1,5 +1,3 @@
#!/bin/bash #!/bin/bash
IFS=$'\n'; set -f find . -iname '*.zip' -exec ~/zip_images_resize.sh '{}' \;
find . -iname *.zip -exec ~/zip_images_resize.sh '{}' \;
unset IFS; set +f