]> mj.ucw.cz Git - gallery.git/blobdiff - gal2/gal-scan
Gallery2: More renames
[gallery.git] / gal2 / gal-scan
index c1b70d09f843b178154a55dbef6094f436372f2a..2cccfe13c82c6f4e2cdc373cef03eb146c497bbb 100755 (executable)
@@ -5,8 +5,9 @@
 use strict;
 use warnings;
 
-use lib '/home/mj/web/gal2';
-use UCW::Gallery;
+use FindBin;
+use lib $FindBin::Bin;
+use UCW::Gallery qw(%CF);
 
 use File::Spec;
 use Image::EXIF;
@@ -29,7 +30,7 @@ if (@ARGV) {
                        my @p = ();
                        while (my $e = readdir D) {
                                my $f = File::Spec->canonpath(File::Spec->catfile($in, $e));
-                               if ($f =~ m{\.jpe?g$}i) {
+                               if ($f =~ m{\.(jpe?g|png)$}i) {
                                        push @p, $f;
                                }
                        }
@@ -47,12 +48,17 @@ if (@ARGV) {
 }
 
 UCW::Gallery::LoadConfig;
+my $orig_prefix = $CF{'OrigDir'};
+$orig_prefix =~ m{/$} or $orig_prefix .= '/';
 
 print "Scanning photos\n";
 my @images = ();
 foreach my $f (@files) {
-       my ($fv, $fd, $ff) = File::Spec->splitpath($f);
-       print "\t$ff: ";
+       my $rel_name = $f;
+       if (substr($rel_name, 0, length $orig_prefix) eq $orig_prefix) {
+               $rel_name = substr($rel_name, length $orig_prefix);
+       }
+       print "\t$rel_name: ";
 
        my $sha = Digest::SHA->new(1);
        $sha->addfile($f) or die "Cannot hash $f\n";
@@ -74,10 +80,10 @@ foreach my $f (@files) {
                        $o = ".";
                }
                push @images, {
-                       file => $f,
+                       file => $rel_name,
                        id => $id,
                        orientation => $o,
-                       xfrm => $UCW::Gallery::CF{'ScanDefaultTransform'},
+                       xfrm => $CF{'ScanDefaultTransform'},
                        title => '',
                };
                print "ori=$o\n";