From 1ec23bc163bef5e743fa15e92a3b4488776b7c30 Mon Sep 17 00:00:00 2001
From: Peter Seiderer <seiderer@localhost.(none)>
Date: Mon, 30 Jan 2012 02:13:32 +0100
Subject: [PATCH 09/11] Add strip from path command line option.

Remove leading path string from shown image name for slides/info
pages and created thumbs/slide image names.
---
 jigl.pl |   32 +++++++++++++++++++++++++-------
 1 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/jigl.pl b/jigl.pl
index b952d82..30f9802 100755
--- a/jigl.pl
+++ b/jigl.pl
@@ -477,6 +477,7 @@ sub setSystemOpts {
             "gb"=>"0",                # go-back
             "gbs"=>"Go Back",         # go-back-string
             "gburl"=>"../index.html", # go-back-url
+            "sfp"=>"",   # strip-from-path
             "theme"=>"default", # theme
             "wd"=>"web",   # web-dir
             "r"=> "0",     # recurse
@@ -618,6 +619,7 @@ sub getCmdOpts {
                'gb|go-back!',
                'gbs|go-back-string=s',
                'gburl|go-back-url=s',
+               'sfp|strip-from-path=s',
                'theme=s',
                'wd|web-dir=s',
                'r|recurse',
@@ -1217,8 +1219,12 @@ sub createNewGalDat {
 
 # convert given path to filename (replace '/' by '_')
 sub convertPath {
-    my $path = $_[0];
+    my (%opts) = %{$_[0]};
+    my $path = $_[1];
+
+    $path =~ s/$opts{sfp}//;
     $path =~ s/\//_/g;
+
     return $path;
 }
 
@@ -1256,7 +1262,7 @@ sub genThumbs {
         # get the name of the file and create the thumbnail filename
         # store the name of the thumbnail for this image in the albumInfo
         $tmpFile = $albumInfo->{images}[$i]->{file};
-        $tmpThumbFile = "$thumbPrefix" . convertPath($tmpFile);
+        $tmpThumbFile = "$thumbPrefix" . convertPath(\%opts,$tmpFile);
         $albumInfo->{images}[$i]->{thumb} = $tmpThumbFile;
 
         # copy and scale if the thumbnail does not already exist or we are
@@ -1335,7 +1341,7 @@ sub genSlides {
     for $i (0 .. $#{$albumInfo->{images}}) {
         # get the name of the file and create the slide filename
         $tmpFile = $albumInfo->{images}[$i]->{file};
-        $tmpSlideFile = "$slidePrefix" . convertPath($tmpFile);
+        $tmpSlideFile = "$slidePrefix" . convertPath(\%opts,$tmpFile);
 
         # store the name of the slide for this image in the albumInfo
         if ($opts{uo}) {
@@ -1440,7 +1446,7 @@ sub genExifInfo {
         $tmpFile = $albumInfo->{images}[$i]->{file};
 
         # set the exif info for the image
-        $albumInfo->{images}[$i]->{exif} = &getExifInfo($tmpFile);
+        $albumInfo->{images}[$i]->{exif} = &getExifInfo(\%opts,$tmpFile);
 
         # set the image description to the exif comment if it exists
         if ($opts{uec}) {
@@ -1483,7 +1489,8 @@ sub genExifInfo {
 # return: the reference to the array of hashes.
 #
 sub getExifInfo {
-    my ($file) = @_;
+    my (%opts) = %{$_[0]};
+    my $file = $_[1];
 
     my @exifArr = ();
 
@@ -1508,6 +1515,9 @@ sub getExifInfo {
 
         # rejoin the line array to preserve any other ':'s in the line
         $line = join ':',@lineArr;
+        if  ($tmpHash{field} eq "File name") {
+            $line =~ s/$opts{sfp}//;
+        }
         # add the value to the hash
         $tmpHash{val} = trimWS($line);
 
@@ -1692,6 +1702,10 @@ Usage: $progName [options] [directories]
 -gburl --go-back-url <url>
                     : URL to use when -gb is enabled. Any URL can be used.
                       Default is '..', the previous directory.
+-sfp --strip-from-path <path>
+                    : Starting path stripped from the shown image path
+                      for slide and info pages.
+                      Default is "".
 --theme <themeName>
                     : Name of theme to use. Themes files are defined as
                       "themeName.theme". You would just enter the "themeName"
@@ -2244,7 +2258,9 @@ sub genSlidePages {
                 }
             }
             if ($line =~ /ORIG-IMAGE-NAME/) {
-                $line =~ s/ORIG-IMAGE-NAME/$albumInfo->{images}[$curr0Index]->{file}/g;
+                $tmpVar = $albumInfo->{images}[$curr0Index]->{file};
+                $tmpVar =~ s/$opts{sfp}//;
+                $line =~ s/ORIG-IMAGE-NAME/$tmpVar/g;
 
             }
             if ($line =~ /NEXT-SLIDE-NAME/) {
@@ -2545,7 +2561,9 @@ sub genInfoPages {
                 }
             }
             if ($line =~ /ORIG-IMAGE-NAME/) {
-                $line =~ s/ORIG-IMAGE-NAME/$albumInfo->{images}[$curr0Index]->{file}/g;
+                $tmpVar = $albumInfo->{images}[$curr0Index]->{file};
+                $tmpVar =~ s/$opts{sfp}//;
+                $line =~ s/ORIG-IMAGE-NAME/$tmpVar/g;
 
             }
             if ($line =~ /NEXT-SLIDE-NAME/) {
-- 
1.7.7

