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