Files
debyl-site/make-thumbs.sh
2019-02-18 16:35:06 -05:00

27 lines
798 B
Bash
Executable File

#!/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