#!/bin/bash

# scale: scales down and converts the images for wmphoto+

#
# CONFIGURATION SECTION BEGINS HERE
#

SourceDirectory="`pwd`"

FileType="jpg"

TargetDirectory="$HOME/.wmphoto+"

#
# CONFIGURATION SECTION ENDS HERE
#

for file in "$SourceDirectory"/*.$FileType
do
    if [ -e "$file" ]
    then
	break
    fi
    echo "There's no *.$FileType file in the given directory."
    exit
done

if [ ! -d "$TargetDirectory" ]
then
    mkdir "$TargetDirectory"
fi

cd "$TargetDirectory"

for source in "$SourceDirectory"/*.$FileType
do
	destination=`echo $source | sed "s#.*/##;s#\.$FileType##"`
	echo "$source --> $destination.xpm.gz"
	touch "$destination"
	nice -n 19 montage "$source" -background gray -colors 256 -geometry 54x54 -size 54x54 -unsharp 0.125 +adjoin "$destination.xpm.gz"
done

