X-Git-Url: http://www.average.org/gitweb/?p=mkgallery.git;a=blobdiff_plain;f=mkgallery.pl;h=1a3688439edf8acf58a7d031b90c9bf85b4f9974;hp=a0cb8eebef6089317ae33056ddfef89ca91737e7;hb=035d9a5f682feb8fc622ec5b3136bb98c91c3ef0;hpb=c1251ffd78703170ddd2fd6e2d14959f64679da0 diff --git a/mkgallery.pl b/mkgallery.pl index a0cb8ee..1a36884 100755 --- a/mkgallery.pl +++ b/mkgallery.pl @@ -33,18 +33,26 @@ use CGI qw/:html *table *Tr *center *div/; use Image::Info qw/image_info dim/; use Term::ReadLine; use Getopt::Long; +use Encode; +use encoding 'utf-8'; +binmode(STDOUT, ":utf8"); -use Image::Magick; +my $haveimagick = eval { require Image::Magick; }; +{ package Image::Magick; } # to make perl compiler happy my @sizes = (160, 640); ###################################################################### +my $incpath; my $debug = 0; my $asktitle = 0; my $noasktitle = 0; -GetOptions('asktitle'=>\$asktitle, +charset("utf-8"); + +GetOptions( 'incpath'=>\$incpath, + 'asktitle'=>\$asktitle, 'noasktitle'=>\$noasktitle, 'debug'=>\$debug); @@ -91,6 +99,10 @@ sub getinc { my $fullpath=shift; # this is not a method my $depth=20; # arbitrary max depth + if ($incpath) { + return $incpath."/.include"; + } + my $inc=".include"; while ( ! -d $fullpath."/".$inc ) { $inc = "../".$inc; @@ -119,11 +131,11 @@ 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) { - my @stat = stat($child->{-fullpath}); - $youngest = $stat[9] if ($youngest < $stat[9]); push(@rimglist,$child); } } @@ -147,12 +159,6 @@ 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; @@ -178,6 +184,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; @@ -340,19 +352,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 { @@ -365,7 +381,7 @@ sub makeaux { my $title = $self->{-info}->{'Comment'}; $title = $name unless ($title); - print "slide: \"$pref\"->\"$name\"->\"$nref\"\n" if ($debug); + print "slide: \"$title\": \"$pref\"->\"$name\"->\"$nref\"\n" if ($debug); # slideshow for my $refresh('static', 'slide') { @@ -398,8 +414,10 @@ sub makeaux { warn "cannot open \"$fn\": $!"; next; } + binmode($F, ":utf8"); if ($refresh eq 'slide') { print $F start_html( + -encoding=>"utf-8", -title=>$title, -bgcolor=>"#808080", -head=>meta({-http_equiv=>'Refresh', @@ -409,6 +427,7 @@ sub makeaux { } else { print $F start_html(-title=>$title, + -encoding=>"utf-8", -bgcolor=>"#808080", -style=>{-src=>$inc."gallery.css"}, ),"\n"; @@ -440,6 +459,7 @@ sub makeaux { } my $imgsrc = sprintf("../.%s/%s",$sizes[0],$name); print $F start_html(-title=>$title, + -encoding=>"utf-8", -style=>{-src=>$inc."gallery.css"},),"\n", start_center,"\n", h1($title),"\n", @@ -463,11 +483,13 @@ sub startindex { warn "cannot open $fn: $!"; return; } + binmode($IND, ":utf8"); $self->{-IND} = $IND; my $inc = $self->{-inc}; my $title = $self->{-title}; print $IND start_html(-title => $title, + -encoding=>"utf-8", -style=>{-src=>[$inc."gallery.css", $inc."lightbox.css"]}, -script=>[{-code=>"var incPrefix='$inc';"},