Created
December 14, 2019 18:40
-
-
Save ayosec/e4433fd0c280c893a999ac8636ba096c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -lt 2 ] | |
then | |
echo "Usage: $0 output inputs*" | |
exit 1 | |
fi | |
set -e | |
OUTPUT="$1" | |
shift | |
SIZE=256 | |
TARGET="$(mktemp -d)" | |
TOTAL=$# | |
NPROCS="$(nproc)" | |
running_jobs() { | |
jobs="\\j" | |
echo -n "${jobs@P}" | |
} | |
waitjob() { | |
wait -n || echo failed | |
echo -en "\rThumbnail $completed of $TOTAL ...\e[K" | |
let completed+=1 | |
} | |
let completed=1 | |
for INPUT in "$@" | |
do | |
if [ $(running_jobs) -ge $NPROCS ] | |
then | |
waitjob | |
fi | |
convert -resize "${SIZE}x${SIZE}" "$INPUT" "$TARGET/${INPUT//\//-}" & | |
done | |
while [ $(running_jobs) -gt 0 ] | |
do | |
waitjob | |
done | |
echo | |
echo Creating "$OUTPUT" | |
montage "$TARGET"/* "$OUTPUT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment