From bac4775c14b8b2161c0866e621a31ee6eae63f35 Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Fri, 3 Mar 2006 14:59:15 +0000 Subject: [PATCH] Image::Info optional, better dependency checking --- README | 19 +++++++++++++------ mkgallery.pl | 45 +++++++++++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/README b/README index 25a0a66..2153bf7 100644 --- a/README +++ b/README @@ -37,7 +37,16 @@ this distribution. Then, chdir to the root of your gallery and run for all subdirectories ("Albums"); if you wish to recreate the titles, remove ".title" files. If you *don't* want "index.html" to be generated in some directory, create a file ".noindex". This way you can preserve -index created by hand or by some other script. +index created by hand or by some other script like "mkindex.pl". + +command-line options: + --debug: print a lot of debugging info to stdout as you run + --asktitle: ask to edit subalbum titles even if there are ".title" files + --noasktitle: don't ask to enter subalbum titles even where ".title" + files are absent. Use partial directories as titles. + +The only way to specify titles for individual pictures is to write +comments into the image files. "mkindex.pl" is a simple script that is completely unrelated to the gallery (theoretically). If your tree starts with YYYY/DD (four @@ -47,15 +56,13 @@ for subdirectories that are not four-digit. Requirements: Image::Info -Image::Magick (might get rid of that later) -Term::ReadLine (not at this moment but planned) +Image::Magick (optional. If not present, will run djeg|pnmscale|cjpeg pipe) +Term::ReadLine Download: svn co svn://svn.average.org/mkgallery/trunk mkgallery TODO: -- build html and indices only if image/directory changed -- make Image::Magick optional -- anything else that I forgot +- any ideas? Eugene Crosser diff --git a/mkgallery.pl b/mkgallery.pl index a0cb8ee..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); @@ -119,11 +120,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 +148,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 +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; @@ -340,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 { -- 2.39.2