#!/bin/bash
# Generate 400px Q80 webp thumbnails into ./thumbs for any root-level *.webp
# that does not yet have one. Idempotent; re-run when a new set is added.
set -e
cd "$(dirname "$0")"
docker run --rm -v "$PWD":/img alpine:latest sh -c '
  apk add --no-cache vips-tools >/dev/null 2>&1
  mkdir -p /img/thumbs
  cd /img
  n=0
  for f in *.webp; do
    [ -e "$f" ] || continue
    [ -f "thumbs/$f" ] && continue
    if vipsthumbnail "$f" --size 400x --output "thumbs/$f[Q=80]" 2>/dev/null; then
      n=$((n+1))
    fi
  done
  echo "generated $n new thumbs; total: $(ls thumbs/*.webp 2>/dev/null | wc -l)"
'
