#!/usr/bin/env bash
set -euo pipefail

# ===== Configuration ===== #
IMGS="imgs"
BAKED="www/imgs"
FAVICON="$BAKED/favicon"
# ========================= #

mkdir -p "$BAKED"
mkdir -p "$FAVICON"

echo 'Generating mirror icon'
magick -background '#000000' -size 100x100 "$IMGS/mirror-icon.svg" "$BAKED/mirror-icon.png"

# resize avatar
echo "Resizing avatar"
magick "$IMGS/c00L_y2k_g1rL.png" -resize 50% "$BAKED/avatar.png"
# crop avatar
echo 'Cropping avatar'
magick "$IMGS/c00L_y2k_g1rL.png" -crop '%wx%w+0+180' "$BAKED/avatar_crop.png"

# create favicon
echo 'Generating favicon.ico'
magick -define icon:auto-resize=16,32,48,64,128,256 -compress zip "$BAKED/avatar_crop.png" "$FAVICON/favicon.ico"
# create separate png favicon alternatives
for n in 16 32 48 64 128 256; do
  echo "Generating favicon-${n}x${n}.png"
  magick "$BAKED/avatar_crop.png" -resize "${n}x${n}" "$FAVICON/favicon-${n}x${n}.png"
done

