X-Git-Url: http://www.average.org/gitweb/?p=mkgallery.git;a=blobdiff_plain;f=mkgallery.pl;h=6ca18eb5a0c199ab1af887a733bf71a1545108f9;hp=822cd49845d1f900e40ef0c54d0911df1cdfc936;hb=2650995d0e1c4a4405a32c0941a88edc2abef644;hpb=2b396eee650aa66eeffb38a2fefdec240741484f diff --git a/mkgallery.pl b/mkgallery.pl index 822cd49..6ca18eb 100755 --- a/mkgallery.pl +++ b/mkgallery.pl @@ -34,7 +34,8 @@ use Image::Info qw/image_info dim/; use Term::ReadLine; use Getopt::Long; -use Image::Magick; +my $haveimagick = eval { require Image::Magick; }; +{ package Image::Magick; } # to make perl compiler happy my @sizes = (160, 640); @@ -108,6 +109,7 @@ sub iterate { my $fullpath .= $self->{-fullpath}; print "iterate in dir $fullpath\n" if ($debug); + my $youngest=0; my @rdirlist; my @rimglist; my $D; @@ -118,6 +120,8 @@ sub iterate { while (my $de = readdir($D)) { next if ($de =~ /^\./); my $child = $self->new($de); + my @stat = stat($child->{-fullpath}); + $youngest = $stat[9] if ($youngest < $stat[9]); if ($child->isdir) { push(@rdirlist,$child); } elsif ($child->isimg) { @@ -169,6 +173,12 @@ sub iterate { $img->makeaux; } +# 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]); + # 5. start building index.html for the directory $self->startindex; @@ -331,19 +341,23 @@ sub isnewer { sub doscaling { my ($src,$dest,$factor,$w,$h) = @_; # this is not a method - my $im = new Image::Magick; - my $err; - print "doscaling $src -> $dest by $factor\n" if ($debug); - $err = $im->Read($src); - unless ($err) { - $im->Scale(width=>$w*$factor,height=>$h*$factor); - $err=$im->Write($dest); - warn "ImageMagick: write \"$dest\": $err" if ($err); - } else { # fallback to command-line tools - warn "ImageMagick: read \"$src\": $err"; + + my $err=1; + if ($haveimagick) { + my $im = new Image::Magick; + print "doscaling $src -> $dest by $factor\n" if ($debug); + if ($err = $im->Read($src)) { + warn "ImageMagick: read \"$src\": $err"; + } else { + $im->Scale(width=>$w*$factor,height=>$h*$factor); + $err=$im->Write($dest); + warn "ImageMagick: write \"$dest\": $err" if ($err); + } + undef $im; + } + if ($err) { # fallback to command-line tools system("djpeg \"$src\" | pnmscale \"$factor\" | cjpeg >\"$dest\""); } - undef $im; } sub makeaux { @@ -361,80 +375,87 @@ sub makeaux { # slideshow for my $refresh('static', 'slide') { my $fn = sprintf("%s/.html/%s-%s.html",$dn,$name,$refresh); - 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, + 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); + } + } + + # info html + 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; } - print $F start_center,"\n", + 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", - 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", + 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); } - 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, - -style=>{-src=>$inc."gallery.css"},),"\n", - 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 {