#!/bin/sh
#
# Copyright (C) 2007-2009 FAUmachine Team <info@faumachine.org>.
# This program is free software. You can redistribute it and/or modify it
# under the terms of the GNU General Public License, either version 2 of
# the License, or (at your option) any later version. See COPYING.
#

#
# convert the ppm file $1 to a png file, setting the ignore color to 
# transparent. Needs image magick (convert)
#

convert_image() {
	IGNORE=$(grep ignore $1 | cut -de -f 2 | cut -d' ' -f 2)
	NAME=$(echo $1 | sed -e 's/ppm$/png/')
	if [ -z "$IGNORE" ]; then
		convert $1 ${NAME}
	else
		ICOL=$(printf "#%06x" $IGNORE)
		convert $1 -transparent $ICOL ${NAME}
	fi
}

usage() {
	echo "faum-ppm-to-png <ppm-file>"
}

if [ $# -eq 1 ]; then
	if [ -f $1 ]; then
		convert_image $1
	fi
else
	usage
fi
