#!/usr/bin/env bash # Generate one topical image per blog post with stable-diffusion.cpp # using Juggernaut XL v9 (photoreal SDXL fine-tune). # euler_a + 1024² + no --mmap is the stable combo on Apple Metal here # (DPM++2M/Karras/--mmap segfault on this M4 — known large-matrix Metal issue). # Outputs WebP into public/blog-images/.webp. set -euo pipefail SD=~/stable-diffusion.cpp/build/bin/sd-cli MODEL=~/sd-models/juggernautXL_v9.safetensors OUT=/Users/jamestwose/Coding/tt-website/public/blog-images TMP=/tmp/sd_blog # Juggernaut README: heavy negatives hurt more than they help — keep it minimal. NEG="text, watermark, signature, low quality, deformed, extra limbs" STEPS=${STEPS:-20} mkdir -p "$OUT" "$TMP" # slug|prompt (prompts use Juggernaut's reliable tokens: Wildlife/Landscape # Photography, Hyperdetailed Photography, Cinematic, natural light) POSTS=( "best-off-leash-areas-for-dogs-in-lagos-and-nearby|Wildlife Photography, a happy dog running off-leash on a wide open sandy path through a Portuguese pine forest, dappled golden sunlight, Hyperdetailed Photography, natural light" "how-to-choose-the-right-walk-for-your-dog-based-on-their-personality-and-needs|Wildlife Photography, a dog owner walking a calm happy dog on a quiet countryside dirt path at sunrise, soft warm light, Hyperdetailed Photography" "how-to-give-a-reactive-dog-a-fulfilling-life-without-avoiding-the-world|Wildlife Photography, a calm dog on a quiet empty woodland trail with plenty of space, soft natural morning light, peaceful, Hyperdetailed Photography" "off-leash-dog-rules-in-portugal-what-you-need-to-know-in-2026|Landscape Photography, a dog on a lead beside a coastal cliff path in Portugal with a blue ocean and sky, summer, Hyperdetailed Photography, Cinematic" "the-importance-of-variety-in-your-dogs-life-and-how-to-do-it-right|Wildlife Photography, a curious dog discovering a new forest trail, sniffing the ground, vibrant green foliage, Hyperdetailed Photography, natural light" "top-10-hikes-to-do-with-your-dog-in-lagos-and-the-algarve|Landscape Photography, a hiker with a dog on a coastal cliff trail in the Algarve Portugal, dramatic golden ocean views at sunset, Hyperdetailed Photography, Cinematic" "walking-your-dog-in-the-algarve-hidden-dangers-every-owner-should-know|Wildlife Photography, a dog walking through a sunlit pine forest in Portugal, dappled light, natural mood, Hyperdetailed Photography" ) i=0 for entry in "${POSTS[@]}"; do slug="${entry%%|*}" prompt="${entry##*|}" i=$((i+1)) png="$TMP/$slug.png" webp="$OUT/$slug.webp" echo "[$i/${#POSTS[@]}] $slug (steps=$STEPS)" "$SD" -m "$MODEL" -p "$prompt" -n "$NEG" \ -H 1024 -W 1024 --steps "$STEPS" --cfg-scale 5.0 --rng std_default \ -s $((i*1000)) -o "$png" >/tmp/sd_blog_$slug.log 2>&1 || { echo " ✗ generation failed (see /tmp/sd_blog_$slug.log)"; exit 1; } cwebp -quiet -resize 1280 0 -q 82 "$png" -o "$webp" 2>/dev/null echo " -> $(ls -lh "$webp" | awk '{print $5}') $webp" done echo "✅ done"