#!/usr/bin/env bash
#
# SuNILab Desktop Background Script
# Copyright (C) 2017-2026 by Thomas Dreibholz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY# without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Contact: thomas.dreibholz@gmail.com

# Bash options:
set -eu

if [ $# -lt 3 ] ; then
   echo >&2 "Usage: $0 output_file caption width"
   exit 1
fi

OUTPUT="$1"
if [ ! -e "$2" ] ; then
   echo >&2 "ERROR: Caption file $2 does not exist!"
   exit 1
fi
CAPTION="$(cat "$2")"
WIDTH="$3"
HEIGHT="$4"

if [ "${MAKE_CAPTION}" = "" ] ; then
   MAKE_CAPTION=gimp-scripts/Make-Caption
fi

height=$((42*HEIGHT/768))   # Height "42" is designed for 1024x768
${MAKE_CAPTION} \
   "${OUTPUT}" "${CAPTION}" "${WIDTH}" "${height}" \
   "Noto Sans Bold" 55 \
   --foreground "#02266b" --background "#ffd700" --transparency 26
