#!/bin/bash
#######################################################################
#                                                                     #
#  Background image  (set in settings.ini)                            #
#                                                                     #
#  DO NOT CHANGE IN HERE !!!                                          #
#                                                                     #
#                                                                     #
#######################################################################


if [ -f "../settings.ini" ]; then
  echo -e "\n$(basename $0): \e[31mOnly works when started via conky!\e[m\n" > /dev/stderr
  exit
fi

if [ -f "./settings.ini" ]; then
  source "./settings.ini"
else
  echo -e "\n$(basename $0): \e[31mNo settings.ini found!\e[m\n" > /dev/stderr
  pkill -f forecast.conky
  exit
fi

if [ "$rcorners" = "yes" ]; then
 rm -f ./background.png
   if [ -f "./clockimages/$ctheme/$bgimage" ]; then
     if [ "$rcornerpixhor" -gt "99999" ]; then rcornerpixhor="99999"; fi
     if [ "$rcornerpixver" -gt "99999" ]; then rcornerpixver="99999"; fi
     imgwidth=$(identify -format "%w" "./clockimages/$ctheme/$bgimage") > /dev/null
     imgheight=$(identify -format "%h" "./clockimages/$ctheme/$bgimage") > /dev/null
     convert -size "$imgwidth"x"$imgheight" xc:none -draw "roundrectangle 0,0,$imgwidth,$imgheight,$rcornerpixhor,$rcornerpixver" /tmp/mask.png
     convert "./clockimages/$ctheme/$bgimage" -matte /tmp/mask.png -compose DstIn -composite ./background.png
   else
     echo -e "$(basename $0):\e[31m No '$bgimage' image found!\e[m  Check settings.ini file..." > /dev/stderr
   fi
else
  cp -f ./clockimages/$ctheme/$bgimage ./background.png
fi

echo "\${lua conky_image ./background.png 0 0 500 445}"
