From aa6bc77462e062774f9b6d3406ca787d0a0db98e Mon Sep 17 00:00:00 2001 From: ange Date: Sat, 28 Jun 2025 07:08:51 +0000 Subject: [PATCH] feat: compress --- .gitignore | 1 + compress | 27 +++++++++++++++++++++++++++ test.sh | 7 +++++++ 3 files changed, 35 insertions(+) create mode 100644 .gitignore create mode 100755 compress create mode 100755 test.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..355164c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*/ diff --git a/compress b/compress new file mode 100755 index 0000000..4870958 --- /dev/null +++ b/compress @@ -0,0 +1,27 @@ +#!/bin/bash -eu + +XARGS=(xargs -0 -P"$(nproc --ignore=4)" -I'{}' bash -c) +function compress() { + local cmd files total newdir progress=0 + + files=("$1"/*) + total="${#files[@]}" + newdir="$(basename "$1")_1080p" + cmd=(magick '{}' -resize x1080 "$newdir/\$(basename '{}')" '>&2;' echo) + mkdir -p "$newdir" + while read -r; do + echo $((++progress * 100 / total)) + done < <(printf '%s\0' "${files[@]}" | "${XARGS[@]}" "${cmd[*]}") +} + +if [ $# = 0 ]; then + mapfile -t < <(zenity --file-selection --multiple --directory --separator='//' | sed 's // \n g') + set -- "${MAPFILE[@]}" +fi + +for DIR in "$@"; do + if [ -d "$DIR" ] && [ -x "$DIR" ]; then + compress "$DIR" | zenity --progress --title="$DIR" --auto-close --time-remaining + fi +done +zenity --info --text=DONE diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..49bc097 --- /dev/null +++ b/test.sh @@ -0,0 +1,7 @@ +#!/bin/bash -e + +mkdir test + +magick -size 3840x2160 xc:black test/000.png + +printf '%s\n' {001..127} | xargs -P0 -I'{}' cp test/000.png test/'{}'.png