summaryrefslogtreecommitdiff
path: root/www/WebMagick/files/patch-aa
blob: 0db347d5ddcb5abc62e61f7208ee88df9ae0eef7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
Index: webmagick.in
===================================================================
RCS file: /cvsroot/webmagick/WebMagick/webmagick.in,v
retrieving revision 1.102
retrieving revision 1.111
diff -u -r1.102 -r1.111
--- webmagick.in	21 Aug 2002 20:36:28 -0000	1.102
+++ webmagick.in	7 Sep 2002 15:57:27 -0000	1.111
@@ -1,6 +1,6 @@
 #! @PERL@
 #
-# $Id: webmagick.in,v 1.102 2002/08/21 20:36:28 clindell Exp $
+# $Id: webmagick.in,v 1.111 2002/09/07 15:57:27 ache Exp $
 #
 # You are looking at the main PERL script for WebMagick, a package to
 # intelligently create HTML and JavaScript index files and imagemaps
@@ -122,7 +122,6 @@
     $opt_lowresformat,
     $opt_lowresgeom,
     $opt_lowresmin,
-    $opt_lowresgeometry,
     $opt_coloralink,
     $opt_colorback,
     $opt_colorfore,
@@ -302,7 +301,7 @@
 $opt_serversidemap = 0;         # Enable server-side maps writting
 				
 $perlVarsVersion = 0; # default this to 0 for it to be overidden by appropriate status files				
-$requiredPerlVarsVersion = 2.2; # need this version to avoid regeneration of files
+$requiredPerlVarsVersion = 2.3; # need this version to avoid regeneration of files
 
 #
 # RC files
@@ -459,11 +458,10 @@
 					#  this size will not be cached.
 
 #PMF: I have added a low resolution of the pictures, by default 640x480
-$opt_lowresgeometry	= '640x480+2+2>'; # Size of low resolution images (width x height)
 $opt_lowres		= 1;		# Cache low resolution images
 $opt_lowresdir		= '.640x480';	# Subdirectory to cache low resolution images in
 $opt_lowresformat	= 'JPEG';	# Format to use for low resolution images
-$opt_lowresgeom		= $opt_lowresgeometry; # Low Resolution Images geometry
+$opt_lowresgeom         = '640x480+2+2>'; # Size of low resolution images (width x height)
 $opt_lowresmin		= 640*480;	# Smallest image to cache in total pixels
 					#  (width * height).  Images smaller than
 					#  this size will not be cached.
@@ -769,7 +767,6 @@
 		'lowresformat=s'		=> \$opt_lowresformat,
 		'lowresgeom=s'		=> \$opt_lowresgeom,
 		'lowresmin=i'		=> \$opt_lowresmin,
-		'lowresgeometry=s'	=> \$opt_lowresgeometry,
 		'coloralink=s'		=> \$opt_coloralink,
 		'colorback=s'		=> \$opt_colorback,
 		'colorfore=s'		=> \$opt_colorfore,
@@ -1214,6 +1211,8 @@
     #	close LOCKFILE;
     #}	
 
+    # XXX: lowres implemented for javascript only
+    $opt_lowres = 0 if !$opt_javascript;
 
     $currentDate = strftime ($opt_msg_date_format, localtime);
 
@@ -1596,8 +1595,8 @@
 	 'address'		=> $opt_address,	 
 	 'anonymous'		=> $opt_anonymous,
 	 'backgroundimg'	=> $opt_icons{'background'},
-	 'cachedir'             => $opt_cachedir,
-	 'lowresdir'             => $opt_lowresdir,
+	 'cachedir'             => !$opt_tables ? "" : $opt_cachedir,
+	 'cacheformat'          => !$opt_tables ? "" : $opt_cacheformat,
 	 'coloralink'		=> $opt_coloralink,
 	 'colorback'		=> $opt_colorback,
 	 'colorfore'		=> $opt_colorfore,
@@ -1903,38 +1902,40 @@
     #
     # Clean up cached thumbnails
     #
-    if( $opt_cache && -d $opt_cachedir ) {
+    if( ($opt_cache || $opt_tables) && -d $opt_cachedir ) {
+        my @extra;
+        my %tarray;
+
         opendir( CACHEDIR, "$opt_cachedir")
             || die("$0: Failed to open directory $opt_cachedir\n$@\n");
         @cacheFiles = grep(!/$excludeRegex/io,readdir( CACHEDIR ));
         closedir( CACHEDIR );
-    }
-    {
-        my @extra;
-        my %tarray;
 
-        grep( $tarray{$_}++, @imgfiles );
+	grep( $tarray{"$_.\L${opt_cacheformat}"}++, @imgfiles );
         @extra = grep( $_ = "$opt_cachedir/$_", grep( ! $tarray{$_}, @cacheFiles ));
-        print( STDERR "Removing extra cache files @extra\n") if $opt_debug;
-        unlink( @extra );
+	if ($#extra >= 0) {
+	    print( STDERR "Removing extra cache files @extra\n") if $opt_debug;
+	    unlink( @extra );
+	}
     }
     #
     # Clean up cached low resolution images
     #
     if( $opt_lowres && -d $opt_lowresdir ) {
+        my @extra;
+        my %tarray;
+
         opendir( LOWRESDIR, "$opt_lowresdir")
             || die("$0: Failed to open directory $opt_lowresdir\n$@\n");
         @lowresFiles = grep(!/$excludeRegex/io,readdir( LOWRESDIR ));
         closedir( LOWRESDIR );
-    }
-    {
-        my @extra;
-        my %tarray;
 
-        grep( $tarray{$_}++, @imgfiles );
+	grep( $tarray{"$_.\L${opt_lowresformat}"}++, @imgfiles );
         @extra = grep( $_ = "$opt_lowresdir/$_", grep( ! $tarray{$_}, @lowresFiles ));
-        print( STDERR "Removing extra lowres files @extra\n") if $opt_debug;
-        unlink( @extra );
+	if ($#extra >= 0) {
+	    print( STDERR "Removing extra lowres files @extra\n") if $opt_debug;
+	    unlink( @extra );
+	}
     }
 
     #
@@ -2597,7 +2598,7 @@
 			# TODO: make sure the thumbnails are created, and get some image sizes
 			# TODO: save the labels in a new array, maybe same with sizes
 			if ( $thumbImageSizes{$pic}) {
-				print (INDEX "<IMG SRC=\"", $opt_cachedir, "/", escapeurl($pic), "\" $thumbImageSizes{$pic} BORDER=0>");				
+				print (INDEX "<IMG SRC=\"", $opt_cachedir, "/", escapeurl($pic), ".\L${opt_cacheformat}", "\" $thumbImageSizes{$pic} BORDER=0>");
 			} else {
 				print (INDEX "<IMG SRC=\"", escapeurl($pic), "\" BORDER=0>");
 			}
@@ -2889,12 +2890,12 @@
     #
     # If caching thumbnails then ensure that directory exists
     #
-    mkdir( $opt_cachedir, 0755 ) if ! -d $opt_cachedir;
+    mkdir( $opt_cachedir, 0755 ) if ($opt_cache || $opt_tables) && ! -d $opt_cachedir;
 
     #
     # If caching low resolution images then ensure that directory exists
     #
-    mkdir( $opt_lowresdir, 0755 ) if ! -d $opt_lowresdir;
+    mkdir( $opt_lowresdir, 0755 ) if $opt_lowres && ! -d $opt_lowresdir;
 
     # Read images into PerlMagick object
     print( STDERR "\nReading images: ", join(' ', @{$imageNames[$pageNumber - 1]}), "\n" )
@@ -2919,217 +2920,37 @@
 READ:       
 	foreach $imagename (@{$imageNames[$pageNumber - 1]}) {
 
-		my ($rc, #return code
-				$width,		# Image width
-				$height,	# Image height
-				$filesize,	# Image file size
-				$magick);
+	    my ($rc,        #return code
+		$width,     # Image width
+		$height,    # Image height
+		$filesize,  # Image file size
+		$magick);
 
+	    if ($opt_lowres) {
 #PMF: resize images using createLowResolutionImage()
 		#first do the low resolution image
-		($rc, $filesize, $width, $height, $magick) = 
-			&createLowResolutionImage ($image, $opt_lowresdir, $imagename, 0, $opt_lowres, 0,
-																 $opt_forcelowres, $opt_lowresgeometry, 
-																 $opt_lowresformat, $opt_lowresmin, 
-																 0, 0);
+		($rc, $filesize, $width, $height, $magick) =
+		    &createLowResolutionImage ($image, $opt_lowresdir, $imagename, 0, 1, 0,
+					       $opt_forcelowres, $opt_lowresgeom,
+					       $opt_lowresformat, $opt_lowresmin,
+					       0, 0);
 		if ($rc == -1) {
-			next READ;
+		    next READ;
 		}
 
 		undef @$image; # Only delete image data, not object
+	    }
 
-		#then do the thumbnail
-		($rc, $filesize, $width, $height, $magick) = 
-			&createLowResolutionImage ($image, $opt_cachedir, $imagename, $opt_cache, 0, $opt_tables,
-																 $opt_forcecache, $opt_thumbgeometry, 
-																 $opt_cacheformat, $opt_cachemin,
-																 $opt_thumbprehook, $opt_thumbposthook);
-		if ($rc	== -1) {
-			next READ;
-		}
-
-#PMF: moved to createLowResolutionImage()
-#	    my (
-#		$width,		# Image width
-#		$height,	# Image height
-#		$base_columns,	# Original width
-#		$base_rows,	# Original height
-#		$class,		# Image class
-#		$comment,	# Image comment
-#		$depth,		# Image color depth
-#		$filesize,	# Image file size
-#		$magick,	# Image magick
-#		);
-#	    #
-#	    # Handle thumbnail cache
-#	    #
-#	    my $cachename = "$opt_cachedir/$imagename";
-
-#	    $newthumb = 1;	# Start presuming that thumbnail is new
-#	    # If we are caching, and cache thumbnail exists and is newer then use it
-#	    # always make cache if doing tables, or if version is not correct
-#	    if ( ($opt_cache || $opt_tables) && ! $opt_forcecache && -f $cachename 
-#	    	&& (fmtime($cachename) >= fmtime($imagename))) {
-#		# Read image
-#		print( STDERR "Reading $cachename ...\n" ) if $opt_debug;
-#		$status = $image->Read("$cachename");
-#		if("$status") {
-#		    undef @$image; # Only delete image data, not object
-#		    handleMagickError( __FILE__, __LINE__, $cachename, $status);
-#		    next READ; # Try to read next image
-#		}
-
-#		# Obtain original image parameters
-#		$comment = $image->Get("comment");
-#		if ($comment =~
-#		    # xv 3.00 & 3.10 format
-#		    /IMGINFO:(\d+)x(\d+) (\S+) file\s+\((\d+) bytes\)/ ) {
-#		    $width = $1;
-#		    $height = $2;
-#		    $magick = $3;
-#		    $filesize = $4;
-#		} else {
-#		    print( STDERR "Failed to grock image info from thumbnail ${cachename}!\n",
-#			  "Removing cache file ...\n" );
-#		    print( STDERR "Run WebMagick again to re-generate the thumbnail.\n" );
-#		    print( STDERR "If problem continues then your ImageMagick is out of date.\n" );
-#		    unlink( $cachename );
-#		}
-
-#		# Indicate that thumbnail came from cache
-#		$newthumb = 0;
-#	    } else {
-#		# Otherwise, read and scale image
-
-#		# Set desired image read size.  The JPEG library will
-#		# read and return a reduced image which is at least
-#		# the size specified (it returns a number of standard
-#		# scaled sizes) but not smaller.
-#		# This uses a feature available in PerlMagick 1.12 and beyond
-#		$status = $image->Set(size=>$opt_thumbgeometry);
-#		handleMagickError( __FILE__, __LINE__, "$opt_thumbgeometry", $status) if "$status";
-		
-#		# Read image
-#		print( STDERR "Reading ${imagename}\[0\] ...\n" ) if $opt_debug;
-#		$status = $image->Read("${imagename}\[0\]");
-#		if("$status" && handleMagickError( __FILE__, __LINE__, $imagename, $status)) {
-#		    undef @$image; # Only delete image data, not object
-#		    print("Trying next image ...\n" );
-#		    next READ; # Try to read next image		    }
-#		}
-
-#		# Scale image and obtain original parameters if not from cache
-#		if( $newthumb ) {
-
-#		    #
-#		    # Apply any PerlMagick operations specified by $opt_thumbprehook
-#		    #
-#		    if( $opt_thumbprehook ) {
-#			print("Evaluating thumbnail pre-hook ...\n$opt_thumbprehook\n" )
-#			    if $opt_debug;
-#			eval $opt_thumbprehook;
-#		    }
-
-#		    # Obtain image parameters
-#		    ( $width, $height, $filesize, $magick, $class, $depth ) =
-#			$image->Get(
-#				    'width',
-#				    'height',
-#				    'filesize',
-#				    'magick',
-#				    'class',
-#				    'depth');
-		    
-#		    if( $opt_debug ) {
-#		      print("Image: ${width}x${height} $class $filesize bytes $magick $depth bits\n");
-#		    }
-
-#		    # Obtain original image size.  This uses a feature
-#		    # available in PerlMagick 1.12 and beyond.  If the
-#		    # feature is not supported then undefined values
-#		    # should be returned.
-#		    ($base_columns, $base_rows) = $image->Get('base-columns', 'base-rows');
-#		    if( defined($base_columns) && defined($base_rows) ) {
-#			$width = $base_columns;
-#			$height = $base_rows;
-#			print("Saving original image size ${base_columns}x${base_rows}\n")
-#			    if $opt_debug;
-#		    }
-
-#		    my $geometry;
-#		    if( $opt_cache ) {
-#			$geometry = $opt_cachegeom;
-#		    } else {
-#			$geometry = $opt_thumbgeometry;
-#		    }
-
-#		    my $opt_sampling = 0; # Set to 1 to enable sampling
-#		    if( $class eq 'PseudoClass' && $opt_sampling ) {
-#			print( STDERR "Sampling $imagename to geometry \"${geometry}>\" ...\n")
-#			    if $opt_debug;
-#			$status = $image->Sample(geometry=>"${geometry}>");
-			
-#		    } else {
-#			print( STDERR "Zooming $imagename with geometry \"${geometry}>\" ...\n")
-#			    if $opt_debug;
-#			$status = $image->Zoom(filter=>"${opt_zoomfilter}",
-#					       blur=>0.6,
-#					       geometry=>"${geometry}>" );
-#		    }
-		    
-#		    if("$status") {
-#			undef @$image; # Only delete image data, not object
-#			handleMagickError( __FILE__, __LINE__, $imagename, $status);
-#			next READ; # Try to read next image
-#		    }
-#		}
-
-#		#
-#		# Apply any PerlMagick operations specified by $opt_thumbposthook
-#		#
-#		if( $opt_thumbposthook ) {
-#		    print("Evaluating thumbnail post-hook ...\n$opt_thumbposthook\n" ) if $opt_debug;
-#		    eval $opt_thumbposthook;
-#		}
-
-#		# If we are caching, thumbnail is new, and image is
-#		# large enough, then write it to thumbnail cache
-#		# if we are using tables, then we cache as long as it's new
-#		if( ($opt_cache || $opt_tables) && $newthumb && ((($width*$height) > $opt_cachemin) || $opt_tables)) {
-		
-
-#		    my $comment="IMGINFO:${width}x${height} ${magick} file  (${filesize} bytes)";
-#		    print( STDERR "Applying image comment:\n${comment}\n") if $opt_debug;
-
-#		    # Apply comment to thumbnail image
-#		    $status = $image->Comment( $comment );
-#		    handleMagickError( __FILE__, __LINE__, $cachename, $status) if "$status";
-		    
-#		    print( STDERR "Writing ${cachename} with format ${opt_cacheformat} ...\n" )
-#			if $opt_debug;
-#                    #
-#                    # Give JPEG files special treatment
-#                    #
-#                    if( $opt_cacheformat eq 'JPEG' || $opt_cacheformat eq 'JPG' ) {
-#		        $status = $image->Write(
-#                                                  filename=>"${opt_cacheformat}:${cachename}",
-#					          interlace=>'None',
-#					          quality=>85
-#                                                );
-#                    } else {
-#		        $status = $image->Write(
-#                                                  filename=>"${opt_cacheformat}:${cachename}"
-#                                               );
-#                    }
-#		    handleMagickError( __FILE__, __LINE__, $cachename, $status) if "$status";
-#		    # TODO: for some reason, the output looks like these are getting put in twice, once with .cache/
-#		    $thumbImageSizes{$imagename} = html_imgsize($cachename);
-		    		    
-#		}
-
-#	    }
+	    #then do the thumbnail
+	    ($rc, $filesize, $width, $height, $magick) =
+		&createLowResolutionImage ($image, $opt_cachedir, $imagename, $opt_cache, 0, $opt_tables,
+					   $opt_forcecache, $opt_thumbgeometry,
+					   $opt_cacheformat, $opt_cachemin,
+					   $opt_thumbprehook, $opt_thumbposthook);
+	    if ($rc == -1) {
+		next READ;
+	    }
 
-	    
 	    #
 	    # Add thumbnail to thumbs array
 	    #
@@ -3205,9 +3026,6 @@
 		    print( STDERR "Montage directory = $directory\n" ) if $opt_debug;
 		    for (split(/\n/,$directory))
 		    {
-			# Eliminate cache dir from path HACK! HACK!
-			s%$opt_cachedir/%% if $opt_cache;
-			my $img = $_;
 			my $x1 = $x;
 			my $y1 = $y;
 			my $x2 = $x+$thumbWidth-1;
@@ -3215,7 +3033,6 @@
 	
 			push(@thumbCoords, "$x1,$y1,$x2,$y2");
 	
-			#print "  <area href=", escapeurl($_), " shape=rect coords=$x1,$y1,", $x2,',', $y2, ">\n";
 			$x+=$thumbWidth;
 			if ($x >= $montageWidth)
 			{
@@ -3845,29 +3662,29 @@
 #returns 0 if everything went fine, -1 if the image does not exist
 sub createLowResolutionImage () {
 	my ($image, $a_dir, $imagename, $a_cache, $a_lowres, $a_tables,
-			$a_force, $a_geometry, $a_cacheformat, $a_cachemin, 
-			$a_prehook, $a_posthook) = @_;
+	    $a_force, $a_geometry, $a_cacheformat, $a_cachemin,
+	    $a_prehook, $a_posthook) = @_;
+
+	my (
+	    $newthumb,              # Set to 1 if new thumbnail
+	    $status         # Return status
+	   );
 
 	my (
-			$newthumb,		# Set to 1 if new thumbnail
-			$status		# Return status
-		 );
-
-	    my (
-		$width,		# Image width
-		$height,	# Image height
-		$base_columns,	# Original width
-		$base_rows,	# Original height
-		$class,		# Image class
-		$comment,	# Image comment
-		$depth,		# Image color depth
-		$filesize,	# Image file size
-		$magick,	# Image magick
-		);
+	    $width,         # Image width
+	    $height,        # Image height
+	    $base_columns,  # Original width
+	    $base_rows,     # Original height
+	    $class,         # Image class
+	    $comment,       # Image comment
+	    $depth,         # Image color depth
+	    $filesize,      # Image file size
+	    $magick         # Image magick
+	   );
 	#
 	# Handle thumbnail/lowres cache
 	#
-	my $cachename = "$a_dir/$imagename";
+	my $cachename = "${a_dir}/${imagename}.\L${a_cacheformat}";
 
 	$newthumb = 1;								# Start presuming that thumbnail is new
 	# If we are caching, and cache thumbnail exists and is newer then use it
@@ -3914,8 +3731,8 @@
 		handleMagickError( __FILE__, __LINE__, "$a_geometry", $status) if "$status";
 		
 		# Read image
-		print( STDERR "Reading ${imagename} ...\n" ) if $opt_debug;
-		$status = $image->Read("${imagename}");
+		print( STDERR "Reading ${imagename}\[0\] with geometry ${a_geometry}...\n" ) if $opt_debug;
+		$status = $image->Read("${imagename}\[0\]");
 		if ("$status" && handleMagickError( __FILE__, __LINE__, $imagename, $status)) {
 			undef @$image;						# Only delete image data, not object
 			print("Trying next image ...\n" );
@@ -3930,20 +3747,20 @@
 			#
 			if ( $a_prehook ) {
 				print("Evaluating thumbnail pre-hook ...\n$a_prehook\n" )
-			    if $opt_debug;
+				    if $opt_debug;
 				eval $a_prehook;
 			}
 
 			# Obtain image parameters
 			( $width, $height, $filesize, $magick, $class, $depth ) =
 				$image->Get(
-										'width',
-										'height',
-										'filesize',
-										'magick',
-										'class',
-										'depth');
-		    
+					    'width',
+					    'height',
+					    'filesize',
+					    'magick',
+					    'class',
+					    'depth');
+
 			if ( $opt_debug ) {
 				print("Image: ${width}x${height} $class $filesize bytes $magick $depth bits\n");
 			}
@@ -3957,30 +3774,28 @@
 				$width = $base_columns;
 				$height = $base_rows;
 				print("Saving original image size ${base_columns}x${base_rows}\n")
-			    if $opt_debug;
+				    if $opt_debug;
 			}
 
 			my $geometry;
-#			if ( $a_cache ) {
-#				$geometry = $opt_cachegeom;
-#			} else {
-#				$geometry = $a_geometry;
-#			}
-			#PMF: I simplified this calculation of the geometry
-			$geometry = $a_geometry;
+			if ($a_cache && !$a_tables && !$a_lowres) {
+				$geometry = $opt_cachegeom;
+			} else {
+				$geometry = $a_geometry;
+			}
 
 			my $a_sampling = 0;			# Set to 1 to enable sampling
 			if ( $class eq 'PseudoClass' && $a_sampling ) {
 				print( STDERR "Sampling $imagename to geometry \"${geometry}>\" ...\n")
-			    if $opt_debug;
+				    if $opt_debug;
 				$status = $image->Sample(geometry=>"${geometry}>");
 			
 			} else {
 				print( STDERR "Zooming $imagename with geometry \"${geometry}>\" ...\n")
-			    if $opt_debug;
+				    if $opt_debug;
 				$status = $image->Zoom(filter=>"${opt_zoomfilter}",
-															 blur=>0.6,
-															 geometry=>"${geometry}>" );
+						       blur=>0.6,
+						       geometry=>"${geometry}>" );
 			}
 		    
 			if ("$status") {
@@ -4000,9 +3815,8 @@
 
 		# If we are caching, thumbnail is new, and image is
 		# large enough, then write it to thumbnail cache
-		# if we are using tables, then we cache as long as it's new
-		if ( ($a_cache || $a_tables || $a_lowres) && $newthumb && ((($width*$height) > $a_cachemin) || $a_tables)) {
-		
+		# if we are using tables or lowres, then we cache as long as it's new
+		if ( ($a_cache || $a_tables || $a_lowres) && $newthumb && ((($width*$height) > $a_cachemin) || ($a_tables || $a_lowres ))) {
 
 			my $comment="IMGINFO:${width}x${height} ${magick} file  (${filesize} bytes)";
 			print( STDERR "Applying image comment:\n${comment}\n") if $opt_debug;
@@ -4011,21 +3825,21 @@
 			$status = $image->Comment( $comment );
 			handleMagickError( __FILE__, __LINE__, $cachename, $status) if "$status";
 		    
-			print( STDERR "Writing ${cachename} with format ${a_cacheformat} ...\n" )
-				if $opt_debug;
+			print( STDERR "Writing ${cachename} ...\n" )
+			    if $opt_debug;
 			#
 			# Give JPEG files special treatment
 			#
 			if ( $a_cacheformat eq 'JPEG' || $a_cacheformat eq 'JPG' ) {
 				$status = $image->Write(
-																filename=>"${a_cacheformat}:${cachename}",
-																interlace=>'None',
-																quality=>85
-															 );
+							filename=>"${a_cacheformat}:${cachename}",
+							interlace=>'None',
+							quality=>85
+						       );
 			} else {
 				$status = $image->Write(
-																filename=>"${a_cacheformat}:${cachename}"
-															 );
+							filename=>"${a_cacheformat}:${cachename}"
+						       );
 			}
 			handleMagickError( __FILE__, __LINE__, $cachename, $status) if "$status";
 			if (! $a_lowres) {
@@ -4036,73 +3850,73 @@
 	}
 	
 	#
-	    # Set image label
-	    #
-	    my $label = '';
-	    if( $opt_thumblabel ne 'false' ) {
-		if( defined( $imageLabels{$imagename} ) ) {
-		    # Set image specific label
-		    $label = $imageLabels{$imagename};
-		} else {
-		    # Set default label
-		    $label = $opt_thumblabel;
-		}
+	# Set image label
+	#
+	my $label = '';
+	if( $opt_thumblabel ne 'false' ) {
+	    if( defined( $imageLabels{$imagename} ) ) {
+		# Set image specific label
+		$label = $imageLabels{$imagename};
+	    } else {
+		# Set default label
+		$label = $opt_thumblabel;
 	    }
+	}
 
-	    if ($label ne '') {
-		my $sizestr;
-		my $kb = 1024;
-		my $mb = $kb * $kb;
-		if( $filesize <= 9999 ) {
-		    # print as bytes
-		    $sizestr = "${filesize}b";
-		} elsif( $filesize <= 9999999 ) {
-		    # print as kilobytes
-		    my $size = int($filesize/$kb);
-		    $sizestr = "${size}kb";	    
-		} else {
-		    # print as megabytes
-		    my $size = int($filesize/$mb);
-		    $sizestr = "${size}Mb";
-		}
-
-		#
-		# Truncate label down to width $opt_thumblabelwidth
-		#
-		my $imagebase;
-		($imagebase = $imagename) =~ s/\.[^\.]*$//g;
-		# %b = file size
-		# %d = directory (not implemented)
-		# %e = extension (not implemented)
-		# %f = full filename
-		# %h = height
-		# %m = magick
-		# %n = filename minus extension
-		# %s = scene number (not implemented)
-		# %t = top of filename (not implemented)
-		# %w = width
-		$label =~ s/%b/$sizestr/g;
-		$label =~ s/%f/$imagename/g;
-		$label =~ s/%h/$height/g;
-		$label =~ s/%m/$magick/g;
-		$label =~ s/%n/$imagebase/g;
-		$label =~ s/%w/$width/g;
-		my @llines = split(/\\n/, $label);
-		grep($_ = substr( $_, 0, $opt_thumblabelwidth), @llines);
-		$label = join("\n", @llines);
-		
-		# put our label into the table image hash 
-		
-		$tableImageLabels{$imagename} = $label;
-		$tableImageLabels{$imagename} =~ s/\n/<BR>/g;
-		
-		print( STDERR "Applying image label: \"${label}\"\n" )
-		    if $opt_debug;
-		$status = $image->Label( $label );
-		handleMagickError( __FILE__, __LINE__, $imagename, $status) if "$status";
+	if ($label ne '') {
+	    my $sizestr;
+	    my $kb = 1024;
+	    my $mb = $kb * $kb;
+	    if( $filesize <= 9999 ) {
+		# print as bytes
+		$sizestr = "${filesize}b";
+	    } elsif( $filesize <= 9999999 ) {
+		# print as kilobytes
+		my $size = int($filesize/$kb);
+		$sizestr = "${size}kb";
+	    } else {
+		# print as megabytes
+		my $size = int($filesize/$mb);
+		$sizestr = "${size}Mb";
 	    }
 
-	
+	    #
+	    # Truncate label down to width $opt_thumblabelwidth
+	    #
+	    my $imagebase;
+	    ($imagebase = $imagename) =~ s/\.[^\.]*$//g;
+	    # %b = file size
+	    # %d = directory (not implemented)
+	    # %e = extension (not implemented)
+	    # %f = full filename
+	    # %h = height
+	    # %m = magick
+	    # %n = filename minus extension
+	    # %s = scene number (not implemented)
+	    # %t = top of filename (not implemented)
+	    # %w = width
+	    $label =~ s/%b/$sizestr/g;
+	    $label =~ s/%f/$imagename/g;
+	    $label =~ s/%h/$height/g;
+	    $label =~ s/%m/$magick/g;
+	    $label =~ s/%n/$imagebase/g;
+	    $label =~ s/%w/$width/g;
+	    my @llines = split(/\\n/, $label);
+	    grep($_ = substr( $_, 0, $opt_thumblabelwidth), @llines);
+	    $label = join("\n", @llines);
+
+	    # put our label into the table image hash
+
+	    $tableImageLabels{$imagename} = $label;
+	    $tableImageLabels{$imagename} =~ s/\n/<BR>/g;
+
+	    print( STDERR "Applying image label: \"${label}\"\n" )
+		if $opt_debug;
+	    $status = $image->Label( $label );
+	    handleMagickError( __FILE__, __LINE__, $imagename, $status) if "$status";
+	}
+
+
 	return 0;
 }
 ######################################################################
@@ -4274,12 +4088,11 @@
   --cachemin         Smallest image to cache in pixels. (default 300*200)
 
 Low resolution images:
-  --[no]lowres        Cache low resolution images (default on)
+  --[no]lowres        Cache low resolution images (default on for Javascript, off otherwise)
   --lowresdir         Subdirectory name to cache low resolution images in (default .640x480)
   --lowresformat      Format of cached low resolution images (default JPEG)
   --lowresgeom        Cache low resolution geometry (default 640x480+2+2)
   --lowresmin         Smallest image to resize in pixels. (default 640*480)
-  --lowresgeometry    Low resolution geometry (widthxheight)
 
 Montage:
   --[no]forcegif     Force imagemap to be in GIF format (default off)