]> www.average.org Git - mkgallery.git/commitdiff
Image::Info optional,
authorEugene Crosser <crosser@average.org>
Fri, 3 Mar 2006 14:59:15 +0000 (14:59 +0000)
committerEugene Crosser <crosser@average.org>
Fri, 3 Mar 2006 14:59:15 +0000 (14:59 +0000)
better dependency checking

README
mkgallery.pl

diff --git a/README b/README
index 25a0a665ec3760ddfc95fe33064b88483cacd01f..2153bf79fc5f260b9d1c7889270ec8c1f344b9c6 100644 (file)
--- 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 <crosser at average dot org>
index a0cb8eebef6089317ae33056ddfef89ca91737e7..6ca18eb5a0c199ab1af887a733bf71a1545108f9 100755 (executable)
@@ -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 {