#!/bin/bash
#
# Photo in conky
# by helmuthdu, paulvictor and Alessandro Roncone

source="/usr/share/backgrounds/"
photo="/tmp/conkyPhoto.png"
systemdir=$( conky-colors --systemdir )
template="$systemdir/icons/ConkyPhoto"
filename=`find $source \( -iname "*.png" -o -iname "*.jpg" \) | shuf -n1`

#choose your theme: 1,2
theme=1

dim="medium"
# Manage dimension flag
if [[ $dim == "small" ]]; then
  geometry="158x100"
  geometry_crop="236x212"
elif [[ $dim == "medium" ]]; then
  geometry="238x148"
  geometry_crop="316x260"
elif [[ $dim == "big" ]]; then
  geometry="318x200"
  geometry_crop="396x312"
fi

rm ${photo}
cp ${filename} ${photo}

convert ${filename} -resize ${geometry}\> \
  -size ${geometry} xc:black +swap \
  -gravity center -composite ${photo}

if [[ $theme -eq 1 ]]; then
  # Theme 1
  convert ${template}/photobg_bg_${dim}.png ${photo} \
    -geometry +11+11 -composite ${photo}
  convert ${photo} ${template}/photobg_shadow_${dim}.png \
    -composite ${photo}
elif [[ $theme -eq 2 ]]; then
  # Theme 2
  convert -page +4+4 ${photo} \
    -bordercolor gray10 -border 1 \
    -background black \( +clone -shadow 40x4+2+2 \) +swap \
    -background none -flatten ${photo}
fi
