#!/usr/bin/env bash

[ $# -lt 2 -o $# -gt 3 ] && {
  echo "Usage: addpic.sh <input_filename> [date] <gallery_filename>"
  echo "Example: $0 ~/Pictures/Screenshot\ 2024-08-18\ at\ 23.32.55.png fusion.png"
  echo "Example: $0 ~/Pictures/Screenshot\ 2024-08-18\ at\ 23.32.55.png 2024-08-18 fusion.png"
  exit
}

infile=$1; shift
date=$(date +%Y-%m-%d)
[ $# -eq 2 ] && { date=$1; shift; }
outfile=$(basename $1); shift

[ -r "$infile" ] || {
  echo "Can't read infile $infile"
  exit
}

cmd="magick \"$infile\" -resize 400x static/img/thumbnails/$date/$outfile"
echo "Running: $cmd"
eval $cmd

cmd="magick \"$infile\" -resize 4000000@\> static/img/fullsize/$date/$outfile"
echo "Running: $cmd"
eval $cmd
