--- /usr/bin/igal	Wed Aug 29 17:44:15 2001
+++ /home/kels/bin/igal	Sun Dec 30 14:59:04 2001
@@ -30,6 +30,8 @@
 # extensive modifications by Robert McQueen <robot101@debian.org>
 # for Debian package. copyright 2000 and 2001
 
+# added --bigxy option - Kelsey Jordahl, 30 Dec 2001
+
 use FileHandle;
 use Getopt::Long;
 
@@ -72,6 +74,7 @@
 $opt_xy = "0";         # scale thumbs to n pixels in their longer dimension
 $opt_help = "0";       # displays brief usage message; same as -h
 $opt_bigy = "0";       # max height of the slides.  use if images are huge.
+$opt_bigxy = "0";      # max dimension of the slides.  use if images are huge.
 $opt_h = "0";
 $opt_www = "0";        # makes everything world-readable
 
@@ -102,6 +105,7 @@
               --www       make all igal files world-readable
               --help      displays this brief help; same as -h
               --bigy <n>  like -y, to shrink huge image slides on the fly
+              --bigxy <n> like --xy, to shrink huge image slides on the fly
 Note:    default values are given in parentheses (where applicable).
 Author:  Eric Pop <epop\@stanford.edu>
 URL:     http://www.stanford.edu/~epop/igal
@@ -109,7 +113,7 @@
 
 # process command-line arguments (overriding defaults above)
 GetOptions('d=s','e=s','y=i','w=i','b=s','p=i','t=i','i=s','q=i','c','C','f','n','k','x',
-           'r','s','h','a','as','ad','xy=i','bigy=i','help','www') or die "$usage";
+           'r','s','h','a','as','ad','xy=i','bigy=i','bigxy=i','help','www') or die "$usage";
 
 die $usage if ($opt_help or $opt_h);
 # deal with the competing -y and --xy options
@@ -338,6 +342,22 @@
 	print " done!\n";
 }
 
+# determine image file sizes
+if (!$opt_bigxy) {
+	print "Determining image sizes ";
+	foreach $file (@imgfiles) {
+		$fullfile = "$opt_d/$file";
+		$temp = `identify -ping -format \"\%wx\%h %b\\n\" \"$fullfile\"`;
+		$temp =~ m/^(\d+)x(\d+) (\d+k?b)/;
+		push(@xdim,$1);	push(@ydim,$2); $temp = $3;
+		# round nicely in kb if identify returned the size in bytes
+		$temp = sprintf ("%.0fkb", $temp/1000) if ($temp =~ s/(\d+)b$/$1/);
+		push(@isiz,$temp);
+		print ".";
+	}
+	print " done!\n";
+}
+
 # scale down slides if the --bigy <n> option was given
 if ($opt_bigy and !($opt_s)) {
 	$opt_f = 1;  # if --bigy <n> is specified, automatically force regeneration
@@ -369,6 +389,37 @@
 	print "... done!\n";
 }
 
+# scale down slides if the --bigxy <n> option was given
+if ($opt_bigxy and !($opt_s)) {
+	$opt_f = 1;  # if --bigxy <n> is specified, automatically force regeneration
+	print "Scaling down big slides and determining new slide sizes:  ";
+	@xdim=(); @ydim=(); @isiz=();    # reset image size arrays
+	for ($i = 0; $i < $nfiles; $i++) {
+		$file = $imgfiles[$i];
+		$fullfile = "$opt_d/$file";
+		die "Can't open $fullfile\n" unless (-r $fullfile);
+		$fullslide = "$opt_d/$slideprefix$file";
+		if ((! -e $fullslide) or $opt_f) {
+			if ($imgext[$i] =~ m/gif/i) {
+				system("cp -f \"$fullfile\" \"$fullslide\"");
+				$command = "mogrify -geometry " . $opt_bigxy . "x$opt_bigxy \"$fullslide\"";
+			} elsif (($imgext[$i] =~ m/jpe?g/i) or ($imgext[$i] =~ m/png/i)) {
+				system("cp -f \"$fullfile\" \"$fullslide\"");
+				$command = "mogrify -quality $opt_q -geometry " . $opt_bigxy . "x$opt_bigxy \"$fullslide\"";
+			}
+			system("$command");
+			print "$slideprefix$file ";
+		}
+		$temp = `identify -ping -format \"\%wx\%h %b\\n\" \"$fullslide\"`;
+		$temp =~ m/^(\d+)x(\d+) (\d+k?b)/;
+		push(@xdim,$1);	push(@ydim,$2); $temp = $3;
+		# round nicely in kb if identify returned the size in bytes
+		$temp = sprintf ("%.0fkb", $temp/1000) if ($temp =~ s/(\d+)b$/$1/);
+		push(@isiz,$temp);
+	}
+	print "... done!\n";
+}
+
 # create the individual slide show files
 if ($opt_s) {
 	print "Linking thumbnails directly to image files...  Making no html slides.\n";
@@ -411,7 +462,7 @@
 		while (defined($line = <SR>)) {
 			$line =~ s/<!--SLIDE-TITLE-->/$title/g;
 			if ($line =~ m/<!--THIS-IMAGE-->/g) {
-				if ($opt_bigy) {
+				if ($opt_bigy|$opt_bigxy) {
 					$slide = $slideprefix . $imgfiles[$i];
 					$line =~ s/(<.*)<!--THIS-IMAGE-->(.)(.*>)/<a href=\"$imgfiles[$i]\">$1$slide$2 width=$xdim[$i] height=$ydim[$i] $3<\/a>/;
 				} else {
@@ -421,7 +472,7 @@
 			$line =~ s/<!--IMAGE-CAPTION-->/$captions[$i]/g;
 			$line =~ s/<!--INDEX-FILE-->/$opt_i/g;
 			if ($i == 0) {
-				if ($opt_bigy) {
+				if ($opt_bigy|$opt_bigxy) {
 					$nextslide = $slideprefix . $imgfiles[1];
 					$line =~ s/<!--NEXT-IMAGE-->/$nextslide/g;
 				} else {
@@ -430,7 +481,7 @@
 				$line =~ s/<!--PREV-SLIDE-->/$slides[$nfiles-1]/g;
 				$line =~ s/<!--NEXT-SLIDE-->/$slides[1]/g;
 			} elsif ($i == $nfiles-1) {
-				if ($opt_bigy) {
+				if ($opt_bigy|$opt_bigxy) {
 					$nextslide = $slideprefix . $imgfiles[0];
 					$line =~ s/<!--NEXT-IMAGE-->/$nextslide/g;
 				} else {
@@ -439,7 +490,7 @@
 				$line =~ s/<!--PREV-SLIDE-->/$slides[$i-1]/g;
 				$line =~ s/<!--NEXT-SLIDE-->/$slides[0]/g;
 			} else {
-				if ($opt_bigy) {
+				if ($opt_bigy|$opt_bigxy) {
 					$nextslide = $slideprefix . $imgfiles[$i+1];
 					$line =~ s/<!--NEXT-IMAGE-->/$nextslide/g;
 				} else {
