Added thumbnail generator bash script

This commit is contained in:
Bastian de Byl
2019-02-18 16:35:06 -05:00
parent a2f443ff07
commit f3fbc96992
4 changed files with 65 additions and 36 deletions

26
make-thumbs.sh Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/bash
CONVERT=$(command -v convert)
if [ ! $CONVERT ]; then
echo "ERROR: imagemagick must be installed!"
exit 1
fi
for i in $(find static/img/*/ -type f -not -path "*thumb*"); do
THUMB_PATH=$(dirname $i)/thumb
IMG_NAME=$(basename $i)
# Generate a thumbnail if the width is greater than 600px
if [ $(identify -format "%w" $i) -gt 600 ]; then
# Create the thumbnail directory fo the image to be made
if [ ! -d $THUMB_PATH ]; then
echo "Creating directory $THUMB_PATH..."
mkdir -p $THUMB_PATH
fi
# Create the thumbnail image
if [ ! -f $THUMB_PATH/$IMG_NAME ]; then
echo "Converting $IMG_NAME to thumbnail..."
$CONVERT -resize 600x $i $THUMB_PATH/$IMG_NAME;
fi
fi
done