X-Git-Url: http://www.average.org/gitweb/?p=mkgallery.git;a=blobdiff_plain;f=mkgallery.pl;h=a0cb8eebef6089317ae33056ddfef89ca91737e7;hp=2f6bc6e5ea0f95371fd5e6c3629a91f29b38069a;hb=c1251ffd78703170ddd2fd6e2d14959f64679da0;hpb=e68c5c22d14964114cf3374a9f8096e3654c2c1f diff --git a/mkgallery.pl b/mkgallery.pl index 2f6bc6e..a0cb8ee 100755 --- a/mkgallery.pl +++ b/mkgallery.pl @@ -28,8 +28,8 @@ package FsObj; use strict; use Carp; -use POSIX qw/getcwd/; -use CGI qw/:html *table *center *div/; +use POSIX qw/getcwd strftime/; +use CGI qw/:html *table *Tr *center *div/; use Image::Info qw/image_info dim/; use Term::ReadLine; use Getopt::Long; @@ -108,6 +108,7 @@ sub iterate { my $fullpath .= $self->{-fullpath}; print "iterate in dir $fullpath\n" if ($debug); + my $youngest=0; my @rdirlist; my @rimglist; my $D; @@ -121,6 +122,8 @@ sub iterate { if ($child->isdir) { push(@rdirlist,$child); } elsif ($child->isimg) { + my @stat = stat($child->{-fullpath}); + $youngest = $stat[9] if ($youngest < $stat[9]); push(@rimglist,$child); } } @@ -144,6 +147,12 @@ sub iterate { $dir->iterate; } +# no need to go beyond this point if the directory timestamp did not +# change since we built index.html file last time. + + my @istat = stat($self->{-fullpath}.'/index.html'); + return unless ($youngest > $istat[9]); + # 3. iterate through images to build cross-links, my $previmg = undef; @@ -216,11 +225,49 @@ sub isimg { } return 0; } + + tryapp12($info) unless ($info->{'ExifVersion'}); + $self->{-isimg} = 1; $self->{-info} = $info; return 1; } +sub tryapp12 { + my $info = shift; # this is not a method + my $app12; + # dirty hack to take care of Image::Info parser strangeness + foreach my $k(keys %$info) { + $app12=substr($k,6).$info->{$k} if ($k =~ /^App12-/); + } + return unless ($app12); # bad luck + my $seenfirstline=0; + foreach my $ln(split /[\r\n]+/,$app12) { + $ln =~ s/[[:^print:]\000]/ /g; + unless ($seenfirstline) { + $seenfirstline=1; + $info->{'Make'}=$ln; + next; + } + my ($k,$v)=split /=/,$ln,2; + if ($k eq 'TimeDate') { + $info->{'DateTime'} = + strftime("%Y:%m:%d %H:%M:%S", localtime($v)) + unless ($v < 0); + } elsif ($k eq 'Shutter') { + $info->{'ExposureTime'} = '1/'.int(1000000/$v+.5); + } elsif ($k eq 'Flash') { + $info->{'Flash'} = $v?'Flash fired':'Flash did not fire'; + } elsif ($k eq 'Type') { + $info->{'Model'} = $v; + } elsif ($k eq 'Version') { + $info->{'Software'} = $v; + } elsif ($k eq 'Fnumber') { + $info->{'FNumber'} = $v; + } + } +} + sub initdir { my $self = shift; my $fullpath = $self->{-fullpath}; @@ -323,82 +370,94 @@ sub makeaux { # slideshow for my $refresh('static', 'slide') { my $fn = sprintf("%s/.html/%s-%s.html",$dn,$name,$refresh); - my $imgsrc = sprintf("../.%s/%s",$sizes[1],$name); - my $fwdref; - my $bakref; - if ($nref) { - $fwdref = sprintf("%s-%s.html",$nref,$refresh); - } else { - $fwdref = '../index.html'; - } - if ($pref) { - $bakref = sprintf("%s-%s.html",$pref,$refresh); - } else { - $bakref = '../index.html'; - } - my $toggleref; - my $toggletext; - if ($refresh eq 'slide') { - $toggleref=sprintf("%s-static.html",$name); - $toggletext = 'Stop!'; - } else { - $toggleref=sprintf("%s-slide.html",$name); - $toggletext = 'Play->'; - } - my $F; - unless (open($F,'>'.$fn)) { - warn "cannot open \"$fn\": $!"; - next; - } - if ($refresh eq 'slide') { - print $F start_html(-title=>$title, + if (isnewer($self->{-fullpath},$fn)) { + my $imgsrc = '../'.$self->{$sizes[1]}; + my $fwdref; + my $bakref; + if ($nref) { + $fwdref = sprintf("%s-%s.html",$nref,$refresh); + } else { + $fwdref = '../index.html'; + } + if ($pref) { + $bakref = sprintf("%s-%s.html",$pref,$refresh); + } else { + $bakref = '../index.html'; + } + my $toggleref; + my $toggletext; + if ($refresh eq 'slide') { + $toggleref=sprintf("%s-static.html",$name); + $toggletext = 'Stop!'; + } else { + $toggleref=sprintf("%s-slide.html",$name); + $toggletext = 'Play->'; + } + my $F; + unless (open($F,'>'.$fn)) { + warn "cannot open \"$fn\": $!"; + next; + } + if ($refresh eq 'slide') { + print $F start_html( + -title=>$title, -bgcolor=>"#808080", -head=>meta({-http_equiv=>'Refresh', -content=>"3; url=$fwdref"}), -style=>{-src=>$inc."gallery.css"}, - ),"\n"; - - } else { - print $F start_html(-title=>$title, + ),"\n"; + + } else { + print $F start_html(-title=>$title, -bgcolor=>"#808080", -style=>{-src=>$inc."gallery.css"}, - ),"\n"; + ),"\n"; + } + print $F start_center,"\n", + h1($title),"\n", + start_table({-class=>'navi'}),start_Tr,"\n", + td(a({-href=>"../index.html"},"Index")),"\n", + td(a({-href=>$bakref},"<<Prev")),"\n", + td(a({-href=>$toggleref},$toggletext)),"\n", + td(a({-href=>$fwdref},"Next>>")),"\n", + end_Tr, + end_table,"\n", + table({-class=>'picframe'}, + Tr(td(img({-src=>$imgsrc})))),"\n", + end_center,"\n", + end_html,"\n"; + close($F); } - print $F start_center,"\n", - h1($title), - a({-href=>"../index.html"},"Index")," | ", - a({-href=>$bakref},"<<Prev")," | ", - a({-href=>$toggleref},$toggletext)," | ", - a({-href=>$fwdref},"Next>>"), - p, - img({-src=>$imgsrc}),"\n", - end_center,"\n", - end_html,"\n"; - close($F); - } - my $fn = sprintf("%s/.html/%s-info.html",$dn,$name); - my $F; - unless (open($F,'>'.$fn)) { - warn "cannot open \"$fn\": $!"; - return; } # info html - my $imgsrc = sprintf("../.%s/%s",$sizes[0],$name); - print $F start_html(-title=>$title,-bgcolor=>"#ffff80", + my $fn = sprintf("%s/.html/%s-info.html",$dn,$name); + if (isnewer($self->{-fullpath},$fn)) { + my $F; + unless (open($F,'>'.$fn)) { + warn "cannot open \"$fn\": $!"; + return; + } + my $imgsrc = sprintf("../.%s/%s",$sizes[0],$name); + print $F start_html(-title=>$title, -style=>{-src=>$inc."gallery.css"},),"\n", - start_center,"\n", - h1($title),"\n", - table(Tr(td(img({-src=>$imgsrc})),td($self->infotable))), - end_table, - end_center,"\n", - end_html,"\n"; - close($F); + start_center,"\n", + h1($title),"\n", + table({-class=>'ipage'}, + Tr(td(img({-src=>$imgsrc})), + td($self->infotable))), + a({-href=>'../index.html'},'Index'),"\n", + end_center,"\n", + end_html,"\n"; + close($F); + } } sub startindex { my $self = shift; my $fn = $self->{-fullpath}.'/index.html'; + my $block = $self->{-fullpath}.'/.noindex'; + $fn = '/dev/null' if ( -f $block ); my $IND; unless (open($IND,'>'.$fn)) { warn "cannot open $fn: $!"; @@ -477,22 +536,24 @@ sub img_entry { my ($w, $h) = dim($info); print $IND start_div({-class=>'ibox',-id=>$name, - -OnClick=>"HideIbox('$name');"}), + -OnClick=>"HideIbox('$name');"}),"\n", + start_div({-class=>'iboxtitle'}), span({-style=>'float: left;'},b("Info for $name")), span({-style=>'float: right;'}, a({-href=>"#",-OnClick=>"HideIbox('$name');"},"Close")), - br({-clear=>'all'}), + br({-clear=>'all'}),"\n", + end_div,"\n", $self->infotable, end_div,"\n"; print $IND table({-class=>'slide'},Tr(td( - a({-href=>".html/$name-info.html", + a({-href=>".html/$name-info.html",-title=>'Image Info', -onClick=>"return showIbox('$name');"},$title), br, a({-href=>$medium,-rel=>"lightbox",-title=>$title}, img({-src=>$thumb})), br, - a({-href=>$name},"($w x $h)"), + a({-href=>$name,-title=>'Original Image'},"($w x $h)"), br))),"\n"; } @@ -522,7 +583,7 @@ sub infotable { 'Model', 'Software', ); - $msg.=start_table."\n"; + $msg.=start_table({-class=>'infotable'})."\n"; foreach my $k(@infokeys) { $msg.=Tr(td($k.":"),td($info->{$k}))."\n" if ($info->{$k}); }