#!/usr/bin/env nu

# Generate low-res placeholders and high-res WebP and JPEG-XL versions of images

let images = (ls ...(glob *.{png,jpg,jpeg}) | get name)

mkdir webp
mkdir jxl

for image in $images {
    let base = ($image | path parse | get stem)
    let ext = ($image | path parse | get extension)

    print $"Generating high-res WebP for ($image)"
    magick $image -quality 85 $"webp/($base).webp"

    print $"Generating high-res JPEG-XL for ($image)"
    magick $image -quality 85 $"jxl/($base).jxl"

    # Resize to 300px width, quality 20
    print $"Generating low-res placeholder for ($image)"
    magick $image -resize 300 -quality 20 $"webp/($base)_low.webp"

    print $"Generating low-res JPEG-XL placeholder for ($image)"
    magick $image -resize 300 -quality 20 $"jxl/($base)_low.jxl"
}

print "Generation complete. Check crates/frontend/assets/webp and crates/frontend/assets/jxl for new files."
