#!/bin/sh
# Convert all gif images to png in current or specified
# directory
case "$1" in
    "-h" | "--help" )
	echo "Usage:"
	echo "  gif2png will convert all gif files of current directory to png"
	echo "  gif2png a_directory will convert all gif files of the specified directory to png"
	echo ""
	;;
    * )
	CURRENT_DIR=""
	# save current directory and change to specified one
	if [ "$1" != "" ]
	    then
	    CURRENT_DIR= pwd
	    cd "$1"
	fi
	# process files
	for file in *.gif
	  do
	  # only if we have some files
	  if [ "$file" != "*.gif" ]
	      then
	      # get filename without extension
	      filename=`echo "$file" | sed s:.gif::`
	      # process conversion if not empty
	      if [ "$filename" != "" ]
		  then
		  convert $filename'.gif' $filename'.png'
	      fi
	  fi
	done
	# restore current directory
	if [ "$CURRENT_DIR" != "" ]
	    then
	    cd "$CURRENT_DIR"
	fi
	;;
esac

exit 0	
