Compare commits

..

3 Commits

Author SHA1 Message Date
d75c797026
feat: graphicsmagick support 2024-04-14 13:53:40 +02:00
1978f835b4
feat: progress bar 2024-04-14 13:47:39 +02:00
aa3c0a5191
feat: tests 2024-04-14 13:40:14 +02:00
5 changed files with 59 additions and 12 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
test*/

9
Dockerfile Normal file
View File

@ -0,0 +1,9 @@
FROM docker.io/debian:12-slim
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
imagemagick \
zenity \
&& rm -rf /var/lib/apt/lists/*
COPY compress /usr/local/bin/
CMD ["compress", "/images/"]

12
compose.yaml Normal file
View File

@ -0,0 +1,12 @@
---
services:
app:
build: .
environment:
- DISPLAY=$DISPLAY
- XAUTHORITY=/.Xauthority
volumes:
- ./test/:/images/:ro
- ./test_1080p/:/images_1080p/
- "$XAUTHORITY:/.Xauthority:ro"
- "/tmp/.X11-unix/:/tmp/.X11-unix/"

View File

@ -9,6 +9,30 @@ function wait_queue() {
done done
} }
function compress() {(
local nb total dir newdir file
cd "$DIR"
dir="$PWD"
total="$(printf '%s\n' * | wc -l)"
newdir="${PWD%/*}/$(basename "$dir")_1080p"
mkdir -p "$newdir"
for file in *; do
"${IDENTIFY[@]}" "$file" 2> /dev/null >&2 \
&& "${CONVERT[@]}" -resize x1080 "$file" "$newdir/$file" &
wait_queue
nb="$(printf '%s\n' "$newdir"/* | wc -l)"
echo "$((nb * 100 / total))"
done
)}
IDENTIFY=(identify)
CONVERT=(convert)
if command -v gm > /dev/null; then
IDENTIFY=(gm "${IDENTIFY[@]}")
CONVERT=(gm "${CONVERT[@]}")
fi
if [ -z "$1" ]; then if [ -z "$1" ]; then
set "$(zenity --file-selection --multiple --directory --separator=' set "$(zenity --file-selection --multiple --directory --separator='
')" > /dev/null ')" > /dev/null
@ -19,16 +43,5 @@ if [ -z "$1" ]; then
fi fi
for DIR in "$@"; do for DIR in "$@"; do
cd "$DIR" compress | zenity --progress --title="$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 done
wait_queue
zenity --info --text="Done"

12
test.sh Executable file
View File

@ -0,0 +1,12 @@
#!/bin/bash -e
CONVERT=(convert)
if command -v gm > /dev/null; then
CONVERT=(gm "${CONVERT[@]}")
fi
mkdir -p test test_1080p
"${CONVERT[@]}" -size 3840x2160 xc:black test/000.png
printf '%s\n' {001..127} | xargs -P0 -I'{}' cp test/000.png test/'{}'.png