mightyscape-1.2/extensions/fablabchemnitz/boxes.py/boxes/scripts/gen_thumbnails.sh

35 lines
846 B
Bash
Raw Normal View History

2022-11-30 15:57:58 +01:00
#!/bin/sh
set -e
STATIC_DIR=../static/samples/
THUMB_WIDTH=200
THUMB_HEIGHT=10000 # height: auto;
thumbnail() {
echo "convert \"$1\" -thumbnail ${THUMB_WIDTH}x${THUMB_HEIGHT} \"${1%.*}-thumb.jpg\""
convert "$1" -thumbnail ${THUMB_WIDTH}x${THUMB_HEIGHT} "${1%.*}-thumb.jpg"
}
[ ! -f "$STATIC_DIR"samples.sha256 ] && touch "$STATIC_DIR"samples.sha256
find "$STATIC_DIR" -name '*.jpg' ! -name '*-thumb.jpg' -type f | while read -r f
do
2024-03-31 18:51:28 +02:00
f_=$(echo "$f" | sed -E -e 's@([.])@\\\1@g')
2022-11-30 15:57:58 +01:00
checksum=$(grep "$f_" "$STATIC_DIR"samples.sha256 || /bin/true)
if [ -n "$checksum" ]
then
echo "$checksum" | sha256sum -c --status || {
echo "File $f changed"
sed -i "/$f_/ c\\
$(sha256sum "$f")
" "$STATIC_DIR"samples.sha256
thumbnail "$f"
}
else
echo "New file $f"
sha256sum "$f" >> "$STATIC_DIR"samples.sha256
thumbnail "$f"
fi
done