Initial commit
This commit is contained in:
Executable
+62
@@ -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"
|
||||
Reference in New Issue
Block a user