#!/bin/bash

# some devices (samsung) create a .jpeg file...rename it to a .JPG file
# eerste commando voorkomt dat ie ook het path zelf probeerd te renamen ipv enkel de inhoud
shopt -s nullglob
for f in /home/kees/public_html/www.gastouder.kooring.com/photoblog/tmp/*.jpeg
do
	rename 's/\.jpeg/\.JPG/' $f
done

# some devices (Iphone) create a .jpg file.....rename it to a .JPG file
# eerste commando voorkomt dat ie ook het path zelf probeerd te renamen ipv enkel de inhoud
shopt -s nullglob
for f in /home/kees/public_html/www.gastouder.kooring.com/photoblog/tmp/*.jpg
do 
	rename 's/\.jpg/\.JPG/' $f
done



# auto rotate all .JPG files to correct orientation
for f in /home/kees/public_html/www.gastouder.kooring.com/photoblog/tmp/*.JPG
do
	exiftran -ai $f
done

#add the watermark to all images
for f in /home/kees/public_html/www.gastouder.kooring.com/photoblog/tmp/*.JPG
do
        convert $f  -pointsize 20 -draw "gravity south fill black  text 0,12 'www.gastouder.kooring.com' fill white  text 1,11 'www.gastouder.kooring.com' " $f
done

# make readable for the world (web server)
chmod go+r /home/kees/public_html/www.gastouder.kooring.com/photoblog/tmp/*.JPG

# move all .JPG files to the actual gallery directory, but create a unique filename based on date and time while doing so. (YYY-MM-DD-HH-MM-SS.name.jpg)
for f in /home/kees/public_html/www.gastouder.kooring.com/photoblog/tmp/*.JPG
do
	mv $f /home/kees/public_html/www.gastouder.kooring.com/photoblog/pictures/$(date +%Y-%m-%d-%H-%M-%S).$(basename $f .JPG).jpg
done

# cleanup after yourself! If any files are left in the tmp/ directory, remove them all (non image files could remain and can be cleaned out)
if [ -f /home/kees/public_html/www.gastouder.kooring.com/photoblog/tmp/* ]
	then rm -f /home/kees/public_html/www.gastouder.kooring.com/photoblog/tmp/*
fi

