image-compressor/compress
2023-10-02 18:27:07 +02:00

35 lines
648 B
Bash
Executable File

#!/bin/bash -e
THREADS="$(nproc --all)"
THREADS="$((THREADS / 2))"
function wait_queue() {
for job in $(jobs -p | awk "FNR>=$THREADS"); do
wait "$job"
done
}
if [ -z "$1" ]; then
set "$(zenity --file-selection --multiple --directory --separator='
')" > /dev/null
fi
if [ -z "$1" ]; then
exit 1
fi
for DIR in "$@"; do
cd "$DIR"
DIR="$PWD"
NEWDIR="${PWD%/*}/$(basename "$DIR")_1080p"
mkdir -p "$NEWDIR"
for FILE in *; do
wait_queue
identify "$FILE" 2> /dev/null >&2 \
&& convert -resize x1080 "$FILE" "$NEWDIR/$FILE" &
done
done
wait_queue
zenity --info --text="Done"