#!/bin/bash

# Get the starting directory (from the current path) ./black
echo -n "Enter the directory name from the twotone directory to base the icons on (probably \"black\") : "
read BASEDIR

# check and make sure it's actually there
if [ ! -d "./$BASEDIR" ]
then
    echo "that is not a directory here ... exiting"
    exit 1;
fi

# get the name of the new directory (from the current path) ./new
echo -n "Enter the name of the new directory : "
read NEWDIR

# check to make sure it is not already there
if [ -d "./$NEWDIR" ]
then
    echo "the directory ./$NEWDIR already exists ... exiting"
    exit 1;
fi

# create the new directory
mkdir ./$NEWDIR

# grab the color from the base directory (black or #000000)
echo -n "Enter the color you want to replace : #"
read OLDCOLOR

# grab the new color we want to create all the icons in
echo -n "Enter the color you want to replace that one with : #"
read NEWCOLOR

# take each *.gif icon from the base directory
# convert it into the same name in the new directory
# replacing the original color with the new one
for f in ./$BASEDIR/*.gif
do
    NAME=`basename $f`
    echo "Converting file : $f to ./$NEWDIR/$NAME"
    echo "convert -fill \"#$NEWCOLOR\" -opaque \"#$OLDCOLOR\" $f ./$NEWDIR/$NAME"
    convert -fill "#$NEWCOLOR" -opaque "#$OLDCOLOR" $f ./$NEWDIR/$NAME
done

