56 lines
1.2 KiB
Bash
Executable File
56 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Generate thumbnail versions of puzzle images.
|
|
# Run from the assets/images/puzzles/ directory.
|
|
#
|
|
# Requires ImageMagick (convert command).
|
|
# Ubuntu/Debian: sudo apt install imagemagick
|
|
# macOS: brew install imagemagick
|
|
#
|
|
# Thumbnails are 576x324 (16:9) and named thumb_<original_filename>.
|
|
|
|
THUMB_WIDTH=576
|
|
THUMB_HEIGHT=324
|
|
|
|
cd "$(dirname "$0")" || exit 1
|
|
|
|
if ! command -v convert &> /dev/null; then
|
|
echo "Error: ImageMagick is not installed."
|
|
echo " Ubuntu/Debian: sudo apt install imagemagick"
|
|
echo " macOS: brew install imagemagick"
|
|
exit 1
|
|
fi
|
|
|
|
count=0
|
|
skipped=0
|
|
|
|
for file in *; do
|
|
# Skip non-files, thumbnails, and this script
|
|
[ -f "$file" ] || continue
|
|
case "$file" in
|
|
thumb_*|*.sh) continue ;;
|
|
esac
|
|
|
|
# Check it's actually an image
|
|
mime=$(file --mime-type -b "$file")
|
|
case "$mime" in
|
|
image/*) ;;
|
|
*) continue ;;
|
|
esac
|
|
|
|
thumb="thumb_${file}"
|
|
|
|
if [ -f "$thumb" ]; then
|
|
echo "SKIP $thumb (already exists)"
|
|
skipped=$((skipped + 1))
|
|
continue
|
|
fi
|
|
|
|
convert "$file" -resize "${THUMB_WIDTH}x${THUMB_HEIGHT}!" -strip "$thumb"
|
|
echo "MADE $thumb"
|
|
count=$((count + 1))
|
|
done
|
|
|
|
echo ""
|
|
echo "Done. Created: $count, Skipped: $skipped"
|