feat: compress

This commit is contained in:
ange 2025-06-28 07:08:51 +00:00
commit aa6bc77462
Signed by: ange
GPG Key ID: 9E0C4157BB7BEB1D
3 changed files with 35 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*/

27
compress Executable file
View File

@ -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

7
test.sh Executable file
View File

@ -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