From f794379b2f0d95538e1d9bf1f43e54db4008c031 Mon Sep 17 00:00:00 2001
From: Peter Seiderer <ps.report@gmx.net>
Date: Tue, 14 Feb 2012 22:56:13 +0100
Subject: [PATCH] Add generate double size slides cmdl option.

Generate double size slides and link to them from the slide image.
---
 jigl.pl |  108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 104 insertions(+), 4 deletions(-)

diff --git a/jigl.pl b/jigl.pl
index 6841e11..444eb2e 100755
--- a/jigl.pl
+++ b/jigl.pl
@@ -48,6 +48,8 @@ my $thumbDir    = "thumbs";            # thumbnail directory
 my $thumbPrefix = "$thumbDir/thumb_";  # thumbnail prefix
 my $slideDir    = "slides";            # slide directory
 my $slidePrefix = "$slideDir/slide_";  # slide prefix
+my $dSlideDir    = "dslides";          # double size slide directory
+my $dSlidePrefix = "$dSlideDir/dslide_";  # double size slide prefix
 my $exifProg    = "jhead";             # program to extract exif info
 my $imgInfoProg = "identify";          # program to display image info
 my $scaleProg   = "convert";           # program to resize images
@@ -166,6 +168,9 @@ foreach $dir (@dirs) {
 
         # generate thumbnails
         &genThumbs(\%opts,$albumInfo);
+	
+        # generate double size slides
+        &genDSlides(\%opts,$albumInfo) if $opts{gds};
 
         # generate slides
         &genSlides(\%opts,$albumInfo) if $opts{gs} or $opts{gi};
@@ -254,7 +259,7 @@ foreach $dir (@dirs) {
             mkdir "$opts{wd}",0755 or die "$dieMsg : $!\n";
         
             print "Copying the files to '$opts{wd}'\n";
-            foreach $dirToCopy ($thumbDir, $slideDir, $themeDir) {
+            foreach $dirToCopy ($thumbDir, $dSlideDir, $slideDir, $themeDir) {
     
                 # if we need to copy that directory, do so
                 if (-d $dirToCopy) {
@@ -468,6 +473,7 @@ sub setSystemOpts {
             "aro"=>"0",  # auto-rotate-originals
             "ard"=>"0",  # auto-rotate-derived
             "gs"=>"1",   # generate-slides
+            "gds"=>"0",  # generate-double-size-slides
             "gi"=>"1",   # generate-info
             "sy"=>"480", # slideY
             "ty"=>"75",  # thumbY
@@ -610,6 +616,7 @@ sub getCmdOpts {
                'aro|auto-rotate-originals!',
                'ard|auto-rotate-derived!',
                'gs|generate-slides!',
+               'gds|generate-double-size-slides!',
                'gi|generate-info!',
                'sy|slideY=i',
                'ty|thumbY=i',
@@ -1308,6 +1315,86 @@ sub genThumbs {
 }
 
 ###########################################################
+# genDSlides - generates double size slide files
+#
+# input: a reference to the options hash
+#        a reference to the albumInfo
+#
+# side effect: update the albumInfo with the name of the double size slide image
+#              update the albumInfo with the XxY dimensions of the double size slide image
+#
+sub genDSlides {
+    my (%opts) = %{$_[0]};
+    my ($albumInfo) = $_[1];
+    print "Generating double size slides\n";
+
+    my $tmpFile = "";          # temp variable to hold image name
+    my $tmpSlideFile = "";     # temp variable to hold slide name
+    my $cmd  = "$scaleProg";   # cmd to run to scale images
+    my $dieMsg = "";           # message to print if we die
+    my $msgPad = "                         "; # 25 spaces
+    my $genCnt = 0;            # number of double size slides generated
+    my $skipCnt = 0;           # number of double size slides existing
+    my $tmpArr = ();           # temporary array
+
+    # create the slide directory if need be
+    if (!(-d $dSlideDir)) {
+        print "The double size slide directory: '$dSlideDir' did not exist. Creating.\n";
+        $dieMsg = "Cannot create the directory '$dSlideDir'.\n";
+        mkdir $dSlideDir,0755 or die "$dieMsg : $!\n";
+    }
+
+    # generate double size slide for each image
+    for $i (0 .. $#{$albumInfo->{images}}) {
+        # get the name of the file and create the slide filename
+        $tmpFile = $albumInfo->{images}[$i]->{file};
+        $tmpSlideFile = "$dSlidePrefix" . convertPath(\%opts,$tmpFile);
+
+        # store the name of the slide for this image in the albumInfo
+        $albumInfo->{images}[$i]->{dSlide} = $tmpSlideFile;
+
+        # scale the image if the slide does not already exist or we are
+        # forcing the generation of the slides and we're not using the orig's
+        if (($opts{fs} or (!(-e $tmpSlideFile)))) {
+            # scale the image to the slide size specs
+            print "\r\(" . ($i+1) . "/" . ($#{$albumInfo->{images}}+1) . "\) Scaling $tmpSlideFile $msgPad";
+            # only scale the slide if it's Y height is greater than
+            # the value of the sy option.
+            my $dsy = 2 * $opts{sy};
+            if ($albumInfo->{images}[$i]->{height} > $dsy) {
+                $cmd = "$scaleProg -scale x$dsy -sharpen 5 \"$tmpFile\" \"$tmpSlideFile\"";
+                $dieMsg = "\nCannot scale the double size slide image!\n";
+                system($cmd) == 0 or die $dieMsg;
+
+                # rotate the thumbnail
+                &rotateImage($tmpSlideFile) if $opts{ard};
+            } else {
+                $dieMsg = "Cannot copy \"$tmpFile\" to \"$tmpSlideFile\"\n";
+                copy $tmpFile,$tmpSlideFile or die "$dieMsg $!\n";
+            }
+
+            # increment the generated count
+            $genCnt++;
+        } else {
+            # increment the skipped count
+            print "\r\(" . ($i+1) . "/" . ($#{$albumInfo->{images}}+1) . "\) Skipping $tmpSlideFile $msgPad";
+            $skipCnt++;
+        }
+
+        # get the image info for the slide
+        @tmpArr = &getImgInfo($albumInfo->{images}[$i]->{dSlide});
+        $albumInfo->{images}[$i]->{dSlidekb} = $tmpArr[0];
+        $albumInfo->{images}[$i]->{dSlidex} = $tmpArr[1];
+        $albumInfo->{images}[$i]->{dSlidey} = $tmpArr[2];
+    }
+
+    print "\r"; # move back to the start of the line
+    print "$genCnt double size slides generated. $msgPad\n" if $genCnt > 0;
+    print "$skipCnt double size slides skipped because they already existed.\n" if $skipCnt > 0;
+    print "Finished generating double size slide images.\n\n";
+}
+
+###########################################################
 # genSlides - generates slide files
 #
 # input: a reference to the options hash
@@ -1559,6 +1646,10 @@ sub newImgInfo {
         slidekb => "", # size in kb of slide the image
         slidex => "",  # width of slide image
         slidey => "",  # height of slide image
+        dSlide => "",   # filename of slide image
+        dSlidekb => "", # size in kb of slide the image
+        dSlidex => "",  # width of slide image
+        dSlidey => "",  # height of slide image
         exif => {}     # hash reference - created later
     };
 }
@@ -1660,6 +1751,10 @@ Usage: $progName [options] [directories]
                       thumbnails instead. If neither slide or info pages are
                       generated, the thumbnails will not link to anything.
                       Default is ENABLED. (can be negated).
+-gds --generate-double-size-slides
+                    : Generate double size slides and link to them from the
+                      slide image.
+                      Default is DISABLED. (can be negated).
 -gi --generate-info : Gererate info pages and link them to the "info" link
                       on the slide pages. If this option is turned off, info
                       pages will not be generated and the "info" link on the
@@ -2293,13 +2388,16 @@ sub genSlidePages {
                 $slideImg =~ s/ /\%20/g; # make any spaces web friendly
                 $slideX   = $albumInfo->{images}[$curr0Index]->{slidex};
                 $slideY   = $albumInfo->{images}[$curr0Index]->{slidey};
+                $dSlideImg = $albumInfo->{images}[$curr0Index]->{dSlide};
+                $dSlideImg =~ s/ /\%20/g; # make any spaces web friendly
 
                 # check to see if we need to link the slide to the original
                 if ($opts{lo}) {
                     $tmpVar = "<a href=\"$origImg\"><img src=\"$slideImg\" width=$slideX height=$slideY border=1 alt=\"$slideImg\"></a>";
+                } elsif ($opts{gds}) {
+                    $tmpVar = "<a href=\"$dSlideImg\"><img src=\"$slideImg\" width=$slideX height=$slideY border=1 alt=\"$slideImg\"></a>";
                 } else {
                     $tmpVar = "<img src=\"$slideImg\" width=$slideX height=$slideY border=1 alt=\"$slideImg\">";
-
                 }
                 $line =~ s/SLIDE-IMAGE/$tmpVar/g;
 
@@ -2616,14 +2714,16 @@ sub genInfoPages {
                 $origImg  =~ s/ /\%20/g; # make any spaces web friendly
                 $slideImg = $albumInfo->{images}[$curr0Index]->{slide};
                 $slideImg =~ s/ /\%20/g; # make any spaces web friendly
-
+                $dSlideImg = $albumInfo->{images}[$curr0Index]->{dSlide};
+                $dSlideImg =~ s/ /\%20/g; # make any spaces web friendly
 
                 # check to see if we need to link the slide to the original
                 if ($opts{lo}) {
                     $tmpVar = "<a href=\"$origImg\"><img src=\"$slideImg\" width=$slideX height=$slideY border=0 alt=\"$slideImg\"></a>";
+                } elsif ($opts{gds}) {
+                    $tmpVar = "<a href=\"$dSlideImg\"><img src=\"$slideImg\" width=$slideX height=$slideY border=1 alt=\"$slideImg\"></a>";
                 } else {
                     $tmpVar = "<img src=\"$slideImg\" width=$slideX height=$slideY border=0 alt=\"$slideImg\">";
-
                 }
                 $line =~ s/INFO-IMAGE/$tmpVar/g;
 
-- 
1.7.7

