Initial commit

This commit is contained in:
2025-11-26 19:57:06 -05:00
commit 76c81548bf
8 changed files with 182 additions and 0 deletions
+14
View File
@@ -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
+9
View File
@@ -0,0 +1,9 @@
#!/bin/bash
for f in ./**
do
pushd "$f"
~/images_resize.sh
popd
done
Executable
+53
View File
@@ -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"
+1
View File
@@ -0,0 +1 @@
find /media/rewt/media/images/ -name '*.rar' -exec ~/rar2zip.sh '{}' \;
+1
View File
@@ -0,0 +1 @@
find /media/rewt/media/incomplete/ -name '*.rar' -exec ~/rar2zip.sh '{}' \;
+37
View File
@@ -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
+62
View File
@@ -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"
+5
View File
@@ -0,0 +1,5 @@
#!/bin/bash
IFS=$'\n'; set -f
find . -iname *.zip -exec ~/zip_images_resize.sh '{}' \;
unset IFS; set +f