maison-diaporama/bin/create-thumbs
2023-01-07 18:32:57 +01:00

52 lines
739 B
Bash
Executable file

#!/bin/sh
usage() {
printf "Usage: %s -s SRC -d DEST\n" "$0"
}
on_interrupt() {
print "Process aborted!\n"
exit 130
}
create_thumb() {
input="$1"
output="$2"
test -f "$input" && convert "$input" -scale 1400x "$output"
}
main() {
while getopts "hs:d:" option; do
case "${option}" in
h) usage; exit 0;;
s) SRC="$OPTARG";;
d) DEST="$OPTARG";;
*) usage; exit 1;;
esac
done
if [ -z "$SRC" ]; then
printf "You must provided the source (directory).\n"
usage
exit 1
fi
if [ -z "$DEST" ]; then
printf "You must provided the destination (directory).\n"
usage
exit 1
fi
for image in "$SRC/"*; do
create_thumb "$image" "$DEST/$(basename "$image")"
done
exit 0
}
trap on_interrupt INT
main "$@"