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