customizable header and footer
[mkgallery.git] / mkgallery.pl
1 #!/usr/bin/perl
2
3 my $version='$Id$';
4
5 # Recursively create image gallery index and slideshow wrappings.
6 # Makes use of modified "slideshow" javascript by Samuel Birch
7 # http://www.phatfusion.net/slideshow/
8
9 # Copyright (c) 2006-2008 Eugene G. Crosser
10
11 #  This software is provided 'as-is', without any express or implied
12 #  warranty.  In no event will the authors be held liable for any damages
13 #  arising from the use of this software.
14 #
15 #  Permission is granted to anyone to use this software for any purpose,
16 #  including commercial applications, and to alter it and redistribute it
17 #  freely, subject to the following restrictions:
18 #
19 #  1. The origin of this software must not be misrepresented; you must not
20 #     claim that you wrote the original software. If you use this software
21 #     in a product, an acknowledgment in the product documentation would be
22 #     appreciated but is not required.
23 #  2. Altered source versions must be plainly marked as such, and must not be
24 #     misrepresented as being the original software.
25 #  3. This notice may not be removed or altered from any source distribution.
26
27 package FsObj;
28
29 use strict;
30 use Carp;
31 use POSIX qw/getcwd strftime/;
32 use CGI qw/:html *table *Tr *td *center *div *Link/;
33 use Image::Info qw/image_info dim/;
34 use Term::ReadLine;
35 use Getopt::Long;
36 use Encode;
37 use encoding 'utf-8';
38 binmode(STDOUT, ":utf8");
39
40 my $haveimagick = eval { require Image::Magick; };
41 { package Image::Magick; }      # to make perl compiler happy
42
43 my $haverssxml = eval { require XML::RSS; };
44 { package XML::RSS; }           # to make perl compiler happy
45
46 my @sizes = (160, 640, 1600);
47
48 ######################################################################
49
50 my $incpath;
51 my $rssobj;
52 my $debug = 0;
53 my $asktitle = 0;
54 my $noasktitle = 0;
55 my $rssfile = "";
56
57 charset("utf-8");
58
59 unless (GetOptions(
60                 'help'=>\&help,
61                 'incpath'=>\$incpath,
62                 'asktitle'=>\$asktitle,
63                 'noasktitle'=>\$noasktitle,
64                 'rssfile=s'=>\$rssfile,
65                 'debug'=>\$debug)) {
66         &help;
67 }
68
69 if ($rssfile && ! $haverssxml) {
70         print STDERR "You need to get XML::RSS from CPAN to use --rssfile\n";
71         exit 1;
72 }
73
74 my $term = new Term::ReadLine "Edit Title";
75
76 FsObj->new(getcwd)->iterate;
77 if ($rssobj) { $rssobj->{'rss'}->save($rssobj->{'file'}); }
78
79 sub help {
80
81         print STDERR <<__END__;
82 usage: $0 [options]
83  --help:        print help message and exit
84  --incpath:     do not try to find .gallery2 diretory upstream, use
85                 specified path (absolute or relavive).  Use with causion.
86  --debug:       print a lot of debugging info to stdout as you run
87  --asktitle:    ask to edit album titles even if there are ".title" files
88  --noasktitle:  don't ask to enter album titles even where ".title"
89                 files are absent.  Use partial directory names as titles.
90  --rssfile=...: build RSS feed for newly added "albums", give name of rss file
91 __END__
92
93         exit 1;
94 }
95
96 sub new {
97         my $this = shift;
98         my $class;
99         my $self;
100         if (ref($this)) {
101                 $class = ref($this);
102                 my $parent = $this;
103                 my $name = shift;
104                 my $fullpath = $parent->{-fullpath}.'/'.$name;
105                 $self = {
106                                 -parent=>$parent,
107                                 -root=>$parent->{-root},
108                                 -depth=>$parent->{-depth}+1,
109                                 -base=>$name,
110                                 -fullpath=>$fullpath,
111                                 -inc=>'../'.$parent->{-inc},
112                                 -rss=>'../'.$parent->{-rss},
113                         };
114         } else {
115                 $class = $this;
116                 my $root=shift;
117                 $self = {
118                                 -depth=>0,
119                                 -root=>$root,
120                                 -fullpath=>$root,
121                                 -inc=>getinc($root),
122                                 -rss=>getrss($root),
123                         };
124         }
125         bless $self, $class;
126         if ($debug) {
127                 print "new $class:\n";
128                 foreach my $k(keys %$self) {
129                         print "\t$k\t=\t$self->{$k}\n";
130                 }
131         }
132         return $self;
133 }
134
135 sub getinc {
136         my $fullpath=shift;     # this is not a method
137         my $depth=20;           # arbitrary max depth
138
139         if ($incpath) {
140                 return $incpath."/.gallery2";
141         }
142
143         my $inc=".gallery2";
144         while ( ! -d $fullpath."/".$inc ) {
145                 $inc = "../".$inc;
146                 last unless ($depth-- > 0);
147         }
148         if ($depth > 0) {
149                 return $inc.'/';                # prefix with trailing slash
150         } else {
151                 return 'NO-.INCLUDE-IN-PATH/';  # won't work anyway
152         }
153 }
154
155 sub getrss {
156         my $fullpath=shift;     # this is not a method
157         my $depth=20;           # arbitrary max depth
158
159         return "" unless $rssfile;
160
161         my $rss=$rssfile;
162         while ( ! -f $fullpath."/".$rss ) {
163                 $rss = "../".$rss;
164                 last unless ($depth-- > 0);
165         }
166         if ($depth > 0) {
167                 $rssobj->{'file'} = $rss;
168                 $rssobj->{'rss'} = new XML::RSS (version=>2);
169                 $rssobj->{'rss'}->parsefile($rss);
170                 my $itemstodel = @{$rssobj->{'rss'}->{'items'}} - 15;
171                 while ($itemstodel-- > 0) {
172                         pop(@{$rssobj->{'rss'}->{'items'}})
173                 }
174                 $rssobj->{'rss'}->save($rssobj->{'file'});
175                 return $rss;
176         } else {
177                 print STDERR "There is no $rssfile in this or parent ".
178                         "directories, you must create one with mkgalrss.pl\n";
179                 exit 1;
180         }
181 }
182
183 sub iterate {
184         my $self = shift;
185         my $fullpath .= $self->{-fullpath};
186         print "iterate in dir $fullpath\n" if ($debug);
187
188         my $youngest=0;
189         my @rdirlist;
190         my @rimglist;
191         my $D;
192         unless (opendir($D,$fullpath)) {
193                 warn "cannot opendir $fullpath: $!";
194                 return;
195         }
196         while (my $de = readdir($D)) {
197                 next if ($de =~ /^\./);
198                 my $child = $self->new($de);
199                 my @stat = stat($child->{-fullpath});
200                 $youngest = $stat[9] if ($youngest < $stat[9]);
201                 if ($child->isdir) {
202                         push(@rdirlist,$child);
203                 } elsif ($child->isimg) {
204                         push(@rimglist,$child);
205                 }
206         }
207         closedir($D);
208         my @dirlist = sort {$a->{-base} cmp $b->{-base}} @rdirlist;
209         undef @rdirlist; # inplace sorting would be handy here
210         my @imglist = sort {$a->{-base} cmp $b->{-base}} @rimglist;
211         undef @rimglist; # optimize away unsorted versions
212         $self->{-firstimg} = $imglist[0];
213
214         print "Dir: $self->{-fullpath}\n" if ($debug);
215
216 # 1. first of all, fill title for this directory and create hidden subdirs
217
218         $self->initdir;
219
220 # 2. recurse into subdirectories to get their titles filled
221 #    before we start writing out subalbum list
222
223         foreach my $dir(@dirlist) {
224                 $dir->iterate;
225         }
226
227 # 3. iterate through images to build cross-links,
228
229         my $previmg = undef;
230         foreach my $img(@imglist) {
231                 # list-linking must be done before generating
232                 # aux html because aux pages rely on prev/next refs
233                 if ($previmg) {
234                         $previmg->{-nextimg} = $img;
235                         $img->{-previmg} = $previmg;
236                 }
237                 $previmg=$img;
238         }
239
240 # 4. create scaled versions and aux html pages
241
242         foreach my $img(@imglist) {
243                 # scaled versions must be generated before aux html
244                 # and main image index because they both rely on
245                 # refs to scaled images and they may be just original
246                 # images, this is not known before we try scaling.
247                 $img->makescaled;
248                 # finally, make aux html pages
249                 $img->makeaux;
250         }
251
252 # no need to go beyond this point if the directory timestamp did not
253 # change since we built index.html file last time.
254
255         my @istat = stat($self->{-fullpath}.'/index.html');
256         return unless ($youngest > $istat[9]);
257
258 # 5. start building index.html for the directory
259
260         $self->startindex;
261
262 # 6. iterate through subdirectories to build subalbums list
263
264         if (@dirlist) {
265                 $self->startsublist;
266                 foreach my $dir(@dirlist) {
267                         $dir->sub_entry;
268                 }
269                 $self->endsublist;
270         }
271
272 # 7. iterate through images to build thumb list
273
274         if (@imglist) {
275                 $self->startimglist;
276                 foreach my $img(@imglist) {
277                         print "Img: $img->{-fullpath}\n" if ($debug);
278                         $img->img_entry;
279                 }
280                 $self->endimglist;
281         }
282
283 # 8. comlplete building index.html for the directory
284
285         $self->endindex;
286 }
287
288 sub isdir {
289         my $self = shift;
290         return ( -d $self->{-fullpath} );
291 }
292
293 sub isimg {
294         my $self = shift;
295         my $fullpath = $self->{-fullpath};
296         return 0 unless ( -f $fullpath );
297         my $info = image_info($fullpath);
298         if (my $error = $info->{error}) {
299                 if (($error !~ "Unrecognized file format") &&
300                     ($error !~ "Can't read head")) {
301                         warn "File \"$fullpath\": $error\n";
302                 }
303                 return 0;
304         }
305
306         tryapp12($info) unless ($info->{'ExifVersion'});
307
308         $self->{-isimg} = 1;
309         $self->{-info} = $info;
310         return 1;
311 }
312
313 sub tryapp12 {
314         my $info = shift;       # this is not a method
315         my $app12;
316         # dirty hack to take care of Image::Info parser strangeness
317         foreach my $k(keys %$info) {
318                 $app12=substr($k,6).$info->{$k} if ($k =~ /^App12-/);
319         }
320         return unless ($app12); # bad luck
321         my $seenfirstline=0;
322         foreach my $ln(split /[\r\n]+/,$app12) {
323                 $ln =~ s/[[:^print:]\000]/ /g;
324                 unless ($seenfirstline) {
325                         $seenfirstline=1;
326                         $info->{'Make'}=$ln;
327                         next;
328                 }
329                 my ($k,$v)=split /=/,$ln,2;
330                 if ($k eq 'TimeDate') {
331                         $info->{'DateTime'} =
332                                 strftime("%Y:%m:%d %H:%M:%S", localtime($v))
333                                                         unless ($v < 0);
334                 } elsif ($k eq 'Shutter') {
335                         $info->{'ExposureTime'} = '1/'.int(1000000/$v+.5);
336                 } elsif ($k eq 'Flash') {
337                         $info->{'Flash'} = $v?'Flash fired':'Flash did not fire';
338                 } elsif ($k eq 'Type') {
339                         $info->{'Model'} = $v;
340                 } elsif ($k eq 'Version') {
341                         $info->{'Software'} = $v;
342                 } elsif ($k eq 'Fnumber') {
343                         $info->{'FNumber'} = $v;
344                 }
345         }
346 }
347
348 sub initdir {
349         my $self = shift;
350         my $fullpath = $self->{-fullpath};
351         for my $subdir(@sizes, 'html') {
352                 my $tdir=sprintf "%s/.%s",$self->{-fullpath},$subdir;
353                 mkdir($tdir,0755) unless ( -d $tdir );
354         }
355         $self->edittitle;
356 }
357
358 sub edittitle {
359         my $self = shift;
360         my $fullpath = $self->{-fullpath};
361         my $title;
362         my $T;
363         if (open($T,'<'.$fullpath.'/.title')) {
364                 $title = <$T>;
365                 $title =~ s/[\r\n]*$//;
366                 close($T);
367         }
368         if ($asktitle || (!$title && !$noasktitle)) {
369                 my $prompt = $self->{-base};
370                 $prompt = '/' unless ($prompt);
371                 my $OUT = $term->OUT || \*STDOUT;
372                 print $OUT "Enter title for $fullpath\n";
373                 $title = $term->readline($prompt.' >',$title);
374                 $term->addhistory($title) if ($title);
375                 if (open($T,'>'.$fullpath.'/.title')) {
376                         print $T $title,"\n";
377                         close($T);
378                 }
379         }
380         unless ($title) {
381                 $title=substr($fullpath,length($self->{-root}));
382         }
383         $self->{-title}=$title;
384         print "title in $fullpath is $title\n" if ($debug);
385 }
386
387 sub makescaled {
388         my $self = shift;
389         my $fn = $self->{-fullpath};
390         my $name = $self->{-base};
391         my $dn = $self->{-parent}->{-fullpath};
392         my ($w, $h) = dim($self->{-info});
393         my $max = ($w > $h)?$w:$h;
394
395         foreach my $size(@sizes) {
396                 my $nref = '.'.$size.'/'.$name;
397                 my $nfn = $dn.'/'.$nref;
398                 my $factor=$size/$max;
399                 if ($factor >= 1) {
400                         $self->{$size}->{'url'} = $name; # unscaled version
401                         $self->{$size}->{'dim'} = [$w, $h];
402                 } else {
403                         $self->{$size}->{'url'} = $nref;
404                         $self->{$size}->{'dim'} = [int($w*$factor+.5),
405                                                         int($h*$factor+.5)];
406                         if (isnewer($fn,$nfn)) {
407                                 doscaling($fn,$nfn,$factor,$w,$h);
408                         }
409                 }
410         }
411 }
412
413 sub isnewer {
414         my ($fn1,$fn2) = @_;                    # this is not a method
415         my @stat1=stat($fn1);
416         my @stat2=stat($fn2);
417         return (!@stat2 || ($stat1[9] > $stat2[9]));
418         # true if $fn2 is absent or is older than $fn1
419 }
420
421 sub doscaling {
422         my ($src,$dest,$factor,$w,$h) = @_;     # this is not a method
423
424         my $err=1;
425         if ($haveimagick) {
426                 my $im = new Image::Magick;
427                 print "doscaling $src -> $dest by $factor\n" if ($debug);
428                 if ($err = $im->Read($src)) {
429                         warn "ImageMagick: read \"$src\": $err";
430                 } else {
431                         $im->Scale(width=>$w*$factor,height=>$h*$factor);
432                         $err=$im->Write($dest);
433                         warn "ImageMagick: write \"$dest\": $err" if ($err);
434                 }
435                 undef $im;
436         }
437         if ($err) {     # fallback to command-line tools
438                 system("djpeg \"$src\" | pnmscale \"$factor\" | cjpeg >\"$dest\"");
439         }
440 }
441
442 sub makeaux {
443         my $self = shift;
444         my $name = $self->{-base};
445         my $dn = $self->{-parent}->{-fullpath};
446         my $pref = $self->{-previmg}->{-base};
447         my $nref = $self->{-nextimg}->{-base};
448         my $inc = $self->{-inc};
449         my $title = $self->{-info}->{'Comment'};
450         $title = $name unless ($title);
451
452         print "slide: \"$title\": \"$pref\"->\"$name\"->\"$nref\"\n" if ($debug);
453
454         # slideshow
455         for my $refresh('static', 'slide') {
456                 my $fn = sprintf("%s/.html/%s-%s.html",$dn,$name,$refresh);
457                 if (isnewer($self->{-fullpath},$fn)) {
458                         my $imgsrc = '../'.$self->{$sizes[1]}->{'url'};
459                         my $fwdref;
460                         my $bakref;
461                         if ($nref) {
462                                 $fwdref = sprintf("%s-%s.html",$nref,$refresh);
463                         } else {
464                                 $fwdref = '../index.html';
465                         }
466                         if ($pref) {
467                                 $bakref = sprintf("%s-%s.html",$pref,$refresh);
468                         } else {
469                                 $bakref = '../index.html';
470                         }
471                         my $toggleref;
472                         my $toggletext;
473                         if ($refresh eq 'slide') {
474                                 $toggleref=sprintf("%s-static.html",$name);
475                                 $toggletext = 'Stop!';
476                         } else {
477                                 $toggleref=sprintf("%s-slide.html",$name);
478                                 $toggletext = 'Play-&gt;';
479                         }
480                         my $F;
481                         unless (open($F,'>'.$fn)) {
482                                 warn "cannot open \"$fn\": $!";
483                                 next;
484                         }
485                         binmode($F, ":utf8");
486                         if ($refresh eq 'slide') {
487                                 print $F start_html(
488                                         -encoding=>"utf-8",
489                                         -title=>$title,
490                                         -bgcolor=>"#808080",
491                                         -head=>meta({-http_equiv=>'Refresh',
492                                                 -content=>"3; url=$fwdref"}),
493                                         -style=>{-src=>$inc."gallery.css"},
494                                         ),"\n",
495                                         comment("Created by ".$version),"\n";
496                                                 
497                         } else {
498                                 print $F start_html(-title=>$title,
499                                         -encoding=>"utf-8",
500                                         -bgcolor=>"#808080",
501                                         -style=>{-src=>$inc."gallery.css"},
502                                         ),"\n",
503                                         comment("Created by ".$version),"\n";
504                         }
505                         print $F start_table({-class=>'navi'}),start_Tr,"\n",
506                                 td(a({-href=>"../index.html"},"Index")),"\n",
507                                 td(a({-href=>$bakref},"&lt;&lt;Prev")),"\n",
508                                 td(a({-href=>$toggleref},$toggletext)),"\n",
509                                 td(a({-href=>$fwdref},"Next&gt;&gt;")),"\n",
510                                 td({-class=>'title'},$title),"\n",
511                                 end_Tr,
512                                 end_table,"\n",
513                                 center(table({-class=>'picframe'},
514                                         Tr(td(img({-src=>$imgsrc,
515                                                    -class=>'standalone',
516                                                    -alt=>$title}))))),"\n",
517                                 end_html,"\n";
518                         close($F);
519                 }
520         }
521
522         # info html
523         my $fn = sprintf("%s/.html/%s-info.html",$dn,$name);
524         if (isnewer($self->{-fullpath},$fn)) {
525                 my $F;
526                 unless (open($F,'>'.$fn)) {
527                         warn "cannot open \"$fn\": $!";
528                         return;
529                 }
530                 my $imgsrc = sprintf("../.%s/%s",$sizes[0],$name);
531                 print $F start_html(-title=>$title,
532                                 -encoding=>"utf-8",
533                                 -style=>{-src=>$inc."gallery.css"},
534                                 -script=>[
535                                         {-src=>$inc."mootools.js"},
536                                         {-src=>$inc."urlparser.js"},
537                                         {-src=>$inc."infopage.js"},
538                                 ]),"\n",
539                         comment("Created by ".$version),"\n",
540                         start_center,"\n",
541                         h1($title),"\n",
542                         table({-class=>'ipage'},
543                                 Tr(td(img({-src=>$imgsrc,
544                                            -class=>'thumbnail',
545                                            -alt=>$title})),
546                                         td($self->infotable))),
547                         a({-href=>'../index.html',-class=>'conceal'},
548                                 'Index'),"\n",
549                         end_center,"\n",
550                         end_html,"\n";
551                 close($F);
552         }
553 }
554
555 sub startindex {
556         my $self = shift;
557         my $fn = $self->{-fullpath}.'/index.html';
558         my $block = $self->{-fullpath}.'/.noindex';
559         $fn = '/dev/null' if ( -f $block );
560         my $IND;
561         unless (open($IND,'>'.$fn)) {
562                 warn "cannot open $fn: $!";
563                 return;
564         }
565         binmode($IND, ":utf8");
566         $self->{-IND} = $IND;
567
568         my $inc = $self->{-inc};
569         my $title = $self->{-title};
570         my $rsslink="";
571         if ($self->{-rss}) {
572                 $rsslink=Link({-rel=>'alternate',
573                                 -type=>'application/rss+xml',
574                                 -title=>'RSS',
575                                 -href=>$self->{-rss}});
576         }
577         print $IND start_html(-title => $title,
578                         -encoding=>"utf-8",
579                         -head=>$rsslink,
580                         -style=>[
581                                 {-src=>$inc."gallery.css"},
582                                 {-src=>$inc."custom.css"},
583                         ],
584                         -script=>[
585                                 {-src=>$inc."mootools.js"},
586                                 {-src=>$inc."overlay.js"},
587                                 {-src=>$inc."urlparser.js"},
588                                 {-src=>$inc."multibox.js"},
589                                 {-src=>$inc."showwin.js"},
590                                 {-src=>$inc."controls.js"},
591                                 {-src=>$inc."show.js"},
592                                 {-src=>$inc."gallery.js"},
593                         ]),"\n",
594                 comment("Created by ".$version),"\n",
595                 start_div({-class => 'indexContainer',
596                                 -id => 'indexContainer'}),
597                 "\n";
598         my $EVL;
599         if (open($EVL,$inc.'header.pl')) {
600                 my $prm;
601                 while (<$EVL>) {
602                         $prm .= $_;
603                 }
604                 close($EVL);
605                 %_ = (
606                         -version        => $version,
607                         -depth          => $self->{-depth},
608                         -title          => $title,
609                         -breadcrumbs    => "breadcrumbs unimplemented",
610                 );
611                 print $IND eval $prm,"\n";
612         } else {
613                 print $IND a({-href=>"../index.html"},"UP"),"\n",
614                         h1({-class=>'title'},$title),"\n",
615         }
616 }
617
618 sub endindex {
619         my $self = shift;
620         my $IND = $self->{-IND};
621
622         print $IND end_div;
623         my $EVL;
624         if (open($EVL,$self->{-inc}.'footer.pl')) {
625                 my $prm;
626                 while (<$EVL>) {
627                         $prm .= $_;
628                 }
629                 close($EVL);
630                 %_ = (
631                         -version        => $version,
632                         -depth          => $self->{-depth},
633                         -title          => $self->{-title},
634                         -breadcrumbs    => "breadcrumbs unimplemented",
635                 );
636                 print $IND eval $prm,"\n";
637         }
638         print $IND end_html,"\n";
639
640         close($IND) if ($IND);
641         undef $self->{-IND};
642         if ($rssobj) {
643                 my $rsstitle=sprintf "%s [%d images, %d subalbums]",
644                                 $self->{-title},
645                                 $self->{-numofimgs},
646                                 $self->{-numofsubs};
647                 my $rsslink=$rssobj->{'rss'}->channel('link')."index.html";
648                 $rssobj->{'rss'}->add_item(
649                         title           => $self->{-title},
650                         link            => $rsslink,
651                         description     => $rsstitle,
652                 );
653         }
654 }
655
656 sub startsublist {
657         my $self = shift;
658         my $IND = $self->{-IND};
659
660         print $IND h2({-class=>"atitle"},"Albums"),"\n",start_table,"\n";
661 }
662
663 sub sub_entry {
664         my $self = shift;
665         my $IND = $self->{-parent}->{-IND};
666         my $name = $self->{-base};
667         my $title = $self->{-title};
668
669         $self->{-parent}->{-numofsubs}++;
670         print $IND Tr(td(a({-href=>$name.'/index.html'},$name)),
671                         td(a({-href=>$name.'/index.html'},$title))),"\n";
672 }
673
674 sub endsublist {
675         my $self = shift;
676         my $IND = $self->{-IND};
677
678         print $IND end_table,"\n",br({-clear=>'all'}),hr,"\n\n";
679 }
680
681 sub startimglist {
682         my $self = shift;
683         my $IND = $self->{-IND};
684         my $first = $self->{-firstimg}->{-base};
685         my $slideref = sprintf(".html/%s-slide.html",$first);
686
687         print $IND h2({-class=>"ititle"},"Images ",
688                 a({-href=>$slideref,-class=>'showStart',-rel=>'i'.$first},
689                         '&gt; slideshow')),"\n";
690 }
691
692 sub img_entry {
693         my $self = shift;
694         my $IND = $self->{-parent}->{-IND};
695         my $name = $self->{-base};
696         my $title = $self->{-info}->{'Comment'};
697         $title = $name unless ($title);
698         my $thumb = $self->{$sizes[0]}->{'url'};
699         my $info = $self->{-info};
700         my ($w, $h) = dim($info);
701
702         my $i=0+$self->{-parent}->{-numofimgs};
703         $self->{-parent}->{-numofimgs}++;
704
705         print $IND a({-name=>$name}),"\n",
706                 start_table({-class=>'slide'}),start_Tr,start_td,"\n",
707                 div({-class=>'slidetitle'},
708                         "\n ",a({-href=>".html/$name-info.html",
709                                 -title=>'Image Info: '.$name,
710                                 -class=>'infoBox'},
711                                 $title),"\n"),"\n",
712                 div({-class=>'slideimage'},
713                         "\n ",a({-href=>".html/$name-static.html",
714                                 -title=>$title,
715                                 -class=>'showImage',
716                                 -rel=>'i'.$name},
717                                 img({-src=>$thumb,
718                                      -class=>'thumbnail',
719                                      -alt=>$title})),"\n"),"\n",
720                 start_div({-class=>'varimages',-id=>'i'.$name,-title=>$title}),"\n";
721         foreach my $sz(@sizes) {
722                 my $src=$self->{$sz}->{'url'};
723                 my $w=$self->{$sz}->{'dim'}->[0];
724                 my $h=$self->{$sz}->{'dim'}->[1];
725                 print $IND "  ",a({-href=>$src,
726                         -class=>"conceal",
727                         -rel=>$w."x".$h,
728                         -title=>"Reduced to ".$w."x".$h},
729                         $w."x".$h)," \n";
730         }
731         print $IND "  ",a({-href=>$name,
732                                 -rel=>$w."x".$h,
733                                 -title=>'Original'},$w."x".$h),
734                 "\n",end_div,"\n",
735                 end_td,end_Tr,end_table,"\n";
736 }
737
738 sub endimglist {
739         my $self = shift;
740         my $IND = $self->{-IND};
741
742         print $IND br({-clear=>'all'}),hr,"\n\n";
743 }
744
745 sub infotable {
746         my $self = shift;
747         my $info = $self->{-info};
748         my $msg='';
749
750         my @infokeys=(
751                 'DateTime',
752                 'ExposureTime',
753                 'FNumber',
754                 'Flash',
755                 'ISOSpeedRatings',
756                 'MeteringMode',
757                 'ExposureProgram',
758                 'FocalLength',
759                 'FileSource',
760                 'Make',
761                 'Model',
762                 'Software',
763         );
764         $msg.=start_table({-class=>'infotable'})."\n";
765         foreach my $k(@infokeys) {
766                 $msg.=Tr(td($k.":"),td($info->{$k}))."\n" if ($info->{$k});
767         }
768         $msg.=end_table."\n";
769 }
770