#!/bin/bash

# Convert a set of image files to new file format
#
# usage:
#
#       example% batch_image_convert <new image type> image1 image2 etc
#
# writes output images image1.* and image2.* where * is the new file type.

name=`basename $0`

# check args
if [ $# -lt 2 ]; then
	echo "usage: $name <new image type> image1 image2 ..."
	echo 
	echo "$name uses converts a group of image files of"
	echo "any image format into a new group of images all of the same"
	echo "image format. It can read almost any standard image format"
	echo "but it can only write v, jpg, tif, ppm and png."

	exit 1
fi

type=$1
shift

# convert each argument
for i in $*; do
	# drop the suffix on the filename
	base=${i%*.*}

	echo "Converting $i to $base.$type ..." 
	if [ -f $base.$type ]; then
		echo "($base.$type already exists, skipping)"
	else
                $VIPSHOME/bin/vips im_copy $i $base.$type
        fi
done
