#!/bin/ksh
#
## Script pour convertir et transférer les images pour mon blog


conversion() {

filename=$1
file=$(basename "$filename")
extension="$(echo "$filename" | awk -F"." '{print $NF}')"
imgpath="/home/phil/www/bonsaiearth/static/img/"

# Valider qu'il s'agit d'une image JPEG
if [ $(echo $extension | grep -E "jpg|JPG|jpeg|JPEG") ];
then
	cp "$filename" "$imgpath"
	/home/phil/bin/opti "$imgpath/$file"
else
	echo "$filename n'est pas une image"
fi
}

for file in "$@" 
do
	conversion "$file"
done
