#!/bin/bash

if [ "$1" ]; then
  SIZE="$1"
else
  echo "USAGE generate_background_gradient.sh SIZE (XxY)"
  exit 1
fi

  FROMCOLOR=$(./random_line.sh /usr/X11R6/lib/X11/rgb.txt | cut -f 3- | sed 's/[ \t]*//g')
  TOCOLOR=$(./random_line.sh /usr/X11R6/lib/X11/rgb.txt | cut -f 3- | sed 's/[ \t]*//g')
  STARTSIZE=$(($(echo $SIZE | awk -Fx '{print $1}')+10))
  STARTSIZE=$STARTSIZE"x"$STARTSIZE

  CONVERTSTRING=" -size ""$STARTSIZE"
  CONVERTSTRING="$CONVERTSTRING"" gradient:""$FROMCOLOR-$TOCOLOR"
  CONVERTSTRING="$CONVERTSTRING"" -rotate ""$(($RANDOM % 360 + 1))"
  CONVERTSTRING="$CONVERTSTRING"" -gravity center -crop ""$SIZE""+0+0"
  CONVERTSTRING="$CONVERTSTRING"" background.png"

  convert $CONVERTSTRING

exit 0
