#!/usr/bin/perl -w

# $Id: make_thumb,v 1.5 2001/04/06 05:16:58 andy Exp $

# make thumbnails..

# you will need to check the path for the convert command below is correct

# if you aren't getting thumbnails, check the apache error_log
# which on redhat systems is in /var/log/httpd/error_log
# on debian: /var/log/apache/error.log

# if you don't have the "convert" command at all, you will need to install
# ImageMagick

#check the size of the input parameters array
#note: $#ARGV - size of input - is the actual number minus one (see perldoc perlvar) so we want to check for at least size 3 , meaning at least 4 arguments
if ($#ARGV < 3) {
	#stamp error logs (since stderr captured by apache process)
	printf STDERR "Usage: make_thumb size_x size_y src_file dest_file\n";
	exit 0;
	}
else {
	$exit_value = make_thumb(@ARGV);
}
exit $exit_value;


sub make_thumb {
	my($sizex, $sizey, @files) = @_;
	#stamp log into the error file.
	printf STDERR  "make_thumb:: x is " .$sizex. " y is " .$sizey. " and files ... @files\n";
	@cmd = ("/usr/bin/X11/convert", "-geometry ".$sizex."x".$sizey." @files");
	#stamp log with actual command.
	printf STDERR "@cmd\n";
	$result = system("@cmd");
	#stamp log with actual result:
	printf STDERR "result from system() call: ". $result;
	if ( ($result >> 8) == 0) {
	 	printf STDERR " returning successful.\n";	
		return 0;
	} else {
		printf STDERR " exiting with failure.\n";
		return 1;
	}
}
