]> git.defcon.no Git - plsgen/commitdiff
Four new features, two bugfixes. Version 0.3 code plsgen-0.3
authorJon Langseth <jon.langseth@lilug.no>
Tue, 14 Dec 2010 12:50:51 +0000 (13:50 +0100)
committerJon Langseth <jon.langseth@lilug.no>
Tue, 14 Dec 2010 12:50:51 +0000 (13:50 +0100)
DONE: Config option for size of view/thumbnail
DONE: Config option to disable arrow-up navigation
DONE: Config option to disable image rescaling ?
DONE: Multithreaded resizing, multiple resizes at the same time
BUGFIX: Version number now gets updated between versions :P

README
plsgen
plsgen.cfg

diff --git a/README b/README
index 2e6e6cd8c5bf886bf60122e5ff92a26ea64a84af..7a9bf1321540c6960e5b7047370309929bf0b608 100644 (file)
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-Perl Simple Gallery Generator v 0.1
+Perl Simple Gallery Generator v 0.3
 ==============================================
 
 Requirements
 ==============================================
 
 Requirements
@@ -32,7 +32,7 @@ somewhere convenient on your Web server.
 
 * Place the template files (index.tpl, full.tpl)
 where You want, I prefer having them located in
 
 * Place the template files (index.tpl, full.tpl)
 where You want, I prefer having them located in
-/usr/loca/share/plsgen
+/usr/local/share/plsgen
 
 * Place the executable script so that execution
 is practical. I place it as /usr/local/bin/plsgen so 
 
 * Place the executable script so that execution
 is practical. I place it as /usr/local/bin/plsgen so 
@@ -124,14 +124,33 @@ E.g.:
   |-- indexstyle.css
    `- rss.php
 
   |-- indexstyle.css
    `- rss.php
 
+Changelog
+-------------------------
+* 0.2 -> 0.3
+# DONE: Config option for size of view/thumbnail
+# DONE: Config option to disable arrow-up navigation
+# DONE: Config option to disable image rescaling ?
+# DONE: Multithreaded resizing, multiple resizes at the same time
+# BUGFIX: Version number now gets updated between versions :P
+
+* 0.1 -> 0.2
+# DONE: filename.txt for file comments
+# DONE: comment.txt for album comments
+# DONE: Save reference to main-index thumbnail.
+# DONE: Add command line option to disable EXIF block output
+# BUGFIX: Now generates for all images, including the last in set.
+# BUGFIX: Performs rotation according to EXIF
 
 Todo-list
 -------------------------
 
 Todo-list
 -------------------------
+# TODO: Stripping of image suffix for HTML file w/config option?
 # TODO: Templating of EXIF
 # TODO: Priority/sorting of EXIF tags
 # TODO: Possibility for hide/show EXIF
 # TODO: Clear old generated files and meta on regen
 # TODO: Use perlmagick et. al instead of convert/jhead..
 # TODO: Templating of EXIF
 # TODO: Priority/sorting of EXIF tags
 # TODO: Possibility for hide/show EXIF
 # TODO: Clear old generated files and meta on regen
 # TODO: Use perlmagick et. al instead of convert/jhead..
+# BUG:  The naive handling of filenames breaks on special characters
+
 
 Lisencing
 -------------------------
 
 Lisencing
 -------------------------
diff --git a/plsgen b/plsgen
index f5876d42bca506c03faeb3c0ec2423407af18fcf..323e5c34682be7be5217f6700206cebe6be9e5e7 100755 (executable)
--- a/plsgen
+++ b/plsgen
@@ -3,14 +3,23 @@ use Image::ExifTool;
 use POSIX;
 use AppConfig;
 use Getopt::Long;
 use POSIX;
 use AppConfig;
 use Getopt::Long;
+use threads;
+use threads::shared;
 use strict;
 
 use strict;
 
+# DONE: Config option for size of view/thumbnail
+# DONE: Config option to disable arrow-up navigation
+# DONE: Config option to disable image rescaling ?
+# DONE: Consider multithreading
+# TODO: Stripping of image suffix for HTML file w/config option?
 # TODO: Templating of EXIF
 # TODO: Priority/sorting of EXIF tags
 # TODO: Possibility for hide/show EXIF
 # TODO: Templating of EXIF
 # TODO: Priority/sorting of EXIF tags
 # TODO: Possibility for hide/show EXIF
-# TODO: RSS support? Delegate that to frontend?
 # TODO: Clear old generated files and meta on regen
 # TODO: Use perlmagick et. al instead of convert/jhead..
 # TODO: Clear old generated files and meta on regen
 # TODO: Use perlmagick et. al instead of convert/jhead..
+# BUG:  The naive handling of filenames breaks on special characters
+
+my $version = "0.3";
 
 # Runtime data
 my $title = undef;
 
 # Runtime data
 my $title = undef;
@@ -19,6 +28,8 @@ my $configfile = undef;
 my $halp = undef;
 my $album_comment = undef;
 my $doexif = 1;
 my $halp = undef;
 my $album_comment = undef;
 my $doexif = 1;
+my $threadcounter = 0;
+share ( $threadcounter );
 
 GetOptions (
        "title=s"       => \$title,
 
 GetOptions (
        "title=s"       => \$title,
@@ -29,7 +40,7 @@ GetOptions (
 );
 if ( $halp )
 {
 );
 if ( $halp )
 {
-       print "\nplsgen version 0.1\n";
+       print "\nplsgen version " . $version . "\n";
        print "Copyright Jon Langseth, BSD lisence\n\n";
        print " --title='Your album title'\n";
        print "     Sets the album title. Title will be stored in .title\n";
        print "Copyright Jon Langseth, BSD lisence\n\n";
        print " --title='Your album title'\n";
        print "     Sets the album title. Title will be stored in .title\n";
@@ -53,16 +64,23 @@ my $full_tpl_file   = $config->full_tpl_file;
 my $index_tpl_file     = $config->index_tpl_file;
 my $css_file           = $config->css_file;
 my $navigation_script  = $config->navigation_script;
 my $index_tpl_file     = $config->index_tpl_file;
 my $css_file           = $config->css_file;
 my $navigation_script  = $config->navigation_script;
+my $up_arrow_navigate  = $config->up_arrow_navigate;
+my $disable_rescale    = $config->disable_rescale;
 my $columns            = $config->columns;
 my $rows               = $config->rows;
 my $thumb_pre          = $config->thumb_pre;
 my $thumb_post                 = $config->thumb_post;
 my $columns            = $config->columns;
 my $rows               = $config->rows;
 my $thumb_pre          = $config->thumb_pre;
 my $thumb_post                 = $config->thumb_post;
+my $thumb_maxwidth     = $config->thumb_maxwidth;
+my $thumb_maxheight    = $config->thumb_maxheight;
+my $view_maxwidth      = $config->view_maxwidth;
+my $view_maxheight     = $config->view_maxheight;
 my $comment_pre        = $config->comment_pre;
 my $comment_post       = $config->comment_post;
 my $idx_prev_text      = $config->idx_prev_text;
 my $idx_next_text      = $config->idx_next_text;
 my $idx_ret_text       = $config->idx_ret_text;
 my $footer_tag                 = $config->footer_tag;
 my $comment_pre        = $config->comment_pre;
 my $comment_post       = $config->comment_post;
 my $idx_prev_text      = $config->idx_prev_text;
 my $idx_next_text      = $config->idx_next_text;
 my $idx_ret_text       = $config->idx_ret_text;
 my $footer_tag                 = $config->footer_tag;
+my $concurrent         = $config->concurrent_threads;
 
 # Get or save the title, depending..
 if ( (not $title) && ( -f ".title" ) )
 
 # Get or save the title, depending..
 if ( (not $title) && ( -f ".title" ) )
@@ -127,8 +145,9 @@ for ( my $i = 1; $i <= $imagecount; $i++)
        my $prev_text = "<a href='" . $previous . ".html'><img src='thumb/" . $previous . "' /></a>";
        my $next_text = "<a href='" . $next . ".html'><img src='thumb/" . $next . "' /></a>";
        my $cur_index_text = "<a href='". $indexfile ."'>" . $idx_ret_text . "</a>";
        my $prev_text = "<a href='" . $previous . ".html'><img src='thumb/" . $previous . "' /></a>";
        my $next_text = "<a href='" . $next . ".html'><img src='thumb/" . $next . "' /></a>";
        my $cur_index_text = "<a href='". $indexfile ."'>" . $idx_ret_text . "</a>";
-       my $current_display = "view/" . $current;
-
+       my $current_display = $current;
+       $current_display = "view/" . $current unless $disable_rescale;
+       
        # Check for, and load comment from FILENAME.txt here..
        my $comment = undef;
        if ( -f $current . ".txt" )
        # Check for, and load comment from FILENAME.txt here..
        my $comment = undef;
        if ( -f $current . ".txt" )
@@ -152,11 +171,20 @@ for ( my $i = 1; $i <= $imagecount; $i++)
        }
        my $exif_text = get_exifblock($exif) if $doexif;
 
        }
        my $exif_text = get_exifblock($exif) if $doexif;
 
-# - - Create thumbnail image (resize to new image)
-       system("convert " . $current . " -geometry '160x120>' thumb/" . $current) unless $htmlonly;
-# - - Create normal display image (resize to new image)
-       system("convert " . $current . " -geometry '800x600>' view/" . $current) unless $htmlonly;
+## - - Create thumbnail and normal view images, support threading
+       if ( not $htmlonly )
+       {
+               $threadcounter++;
+               my $thread = threads->create (
+                       \&scale_image_t, 
+                       $current, $thumb_maxwidth, $thumb_maxheight,
+                       $view_maxwidth, $view_maxheight, $disable_rescale);
 
 
+               if ( $threadcounter >= $concurrent )
+               {
+                       foreach my $thr ( threads->list() ) { $thr->join(); }
+               }
+       }
 # - - Save a reference to the "primary image"
        if ( not -f ".indeximage" )
        {
 # - - Save a reference to the "primary image"
        if ( not -f ".indeximage" )
        {
@@ -171,10 +199,8 @@ for ( my $i = 1; $i <= $imagecount; $i++)
        {
                if ( $previous ) { $_ =~ s/%\{previous\}/$prev_text/; } 
                else { $_ =~ s/%\{previous\}//; } 
        {
                if ( $previous ) { $_ =~ s/%\{previous\}/$prev_text/; } 
                else { $_ =~ s/%\{previous\}//; } 
-
                if ( $next ) { $_ =~ s/%\{next\}/$next_text/; }
                else { $_ =~ s/%\{next\}//; }
                if ( $next ) { $_ =~ s/%\{next\}/$next_text/; }
                else { $_ =~ s/%\{next\}//; }
-
                $_ =~ s/%\{index\}/$cur_index_text/;
                $_ =~ s/%\{title\}/$title/;
                $_ =~ s/%\{main_meta\}/$main_meta/;
                $_ =~ s/%\{index\}/$cur_index_text/;
                $_ =~ s/%\{title\}/$title/;
                $_ =~ s/%\{main_meta\}/$main_meta/;
@@ -212,6 +238,9 @@ for ( my $i = 1; $i <= $imagecount; $i++)
 }
 $thumbs .= "</div>";
 make_index( $index_tpl_file, $indexcount, $indexes, $thumbs, $album_comment );
 }
 $thumbs .= "</div>";
 make_index( $index_tpl_file, $indexcount, $indexes, $thumbs, $album_comment );
+
+printf ("Waiting for %d threads to finish\n", $threadcounter) if $threadcounter;
+foreach my $thr ( threads->list() ) { $thr->join(); }
 # Done.
 
 
 # Done.
 
 
@@ -300,8 +329,6 @@ sub get_exifdata ($)
        $exif->{'ExposureCompensation'} = $info->{'ExposureCompensation'};
        $exif->{'Flash'} = $info->{'Flash'};
        $exif->{'FocalLength'} = $info->{'FocalLength'};
        $exif->{'ExposureCompensation'} = $info->{'ExposureCompensation'};
        $exif->{'Flash'} = $info->{'Flash'};
        $exif->{'FocalLength'} = $info->{'FocalLength'};
-       #$exif->{'ColorSpace'} = $info->{'ColorSpace'};
-       #$exif->{'FileSource'} = $info->{'FileSource'};
        $exif->{'ExposureMode'} = $info->{'ExposureMode'};
        $exif->{'Macro'} = $info->{'Macro'};
        $exif->{'LensType'} = $info->{'LensType'};
        $exif->{'ExposureMode'} = $info->{'ExposureMode'};
        $exif->{'Macro'} = $info->{'Macro'};
        $exif->{'LensType'} = $info->{'LensType'};
@@ -350,12 +377,34 @@ sub gen_navscript
        my $scriptbuffer = "<script type='text/javascript'>\n";
        $scriptbuffer .= "\tnav_reg_prev('" . $prev . "');\n" if $prev;
        $scriptbuffer .= "\tnav_reg_next('" . $next . "');\n" if $next;
        my $scriptbuffer = "<script type='text/javascript'>\n";
        $scriptbuffer .= "\tnav_reg_prev('" . $prev . "');\n" if $prev;
        $scriptbuffer .= "\tnav_reg_next('" . $next . "');\n" if $next;
-       $scriptbuffer .= "\tnav_reg_index('" . $index . "');\n" if $index;
+       if ( $up_arrow_navigate == 1 )
+       {
+               $scriptbuffer .= "\tnav_reg_index('" . $index . "');\n" if $index;
+       }
        $scriptbuffer .= "\tnav_reg_onkeypress();\n";
        $scriptbuffer .= "</script>\n";
        return $scriptbuffer;
 }
 
        $scriptbuffer .= "\tnav_reg_onkeypress();\n";
        $scriptbuffer .= "</script>\n";
        return $scriptbuffer;
 }
 
+sub scale_image_t
+{
+       my $current = shift;
+       my $thumb_maxwidth = shift;
+       my $thumb_maxheight = shift;
+       my $view_maxwidth = shift;
+       my $view_maxheight = shift;
+       my $disable_rescale = shift;
+
+       my $tgeom = $thumb_maxwidth . "x" . $thumb_maxheight;
+       my $vgeom = $view_maxwidth . "x" . $view_maxheight;
+       # - - Create thumbnail image (resize to new image)
+       system("convert " . $current . " -geometry '" . $tgeom . ">' thumb/" . $current);
+       # - - Create normal display image (resize to new image)
+       system("convert " . $current . " -geometry '" . $vgeom . ">' view/" . $current) unless $disable_rescale;
+       $threadcounter--;
+
+}
+
 sub get_config
 {
        # My standard way of implementing AppConfig use ...
 sub get_config
 {
        # My standard way of implementing AppConfig use ...
@@ -384,30 +433,53 @@ sub get_config
        $cfg->full_tpl_file("/usr/local/share/plsgen/full.tpl");
        $cfg->define('index_tpl_file');
        $cfg->index_tpl_file("/usr/local/share/plsgen/index.tpl");
        $cfg->full_tpl_file("/usr/local/share/plsgen/full.tpl");
        $cfg->define('index_tpl_file');
        $cfg->index_tpl_file("/usr/local/share/plsgen/index.tpl");
+
        $cfg->define('css_file');
        $cfg->css_file("../style.css");
        $cfg->define('navigation_script');
        $cfg->navigation_script("../nav.js");
        $cfg->define('css_file');
        $cfg->css_file("../style.css");
        $cfg->define('navigation_script');
        $cfg->navigation_script("../nav.js");
+
+       $cfg->define('up_arrow_navigate');
+       $cfg->up_arrow_navigate(1);
+
        $cfg->define('columns');
        $cfg->columns(4);
        $cfg->define('rows');
        $cfg->rows(3);
        $cfg->define('columns');
        $cfg->columns(4);
        $cfg->define('rows');
        $cfg->rows(3);
+
+       $cfg->define('concurrent_threads');
+       $cfg->concurrent_threads(1);
+
+        $cfg->define('thumb_maxwidth');
+       $cfg->thumb_maxwidth(160);
+        $cfg->define('thumb_maxheight');
+       $cfg->thumb_maxheight(120);
+        $cfg->define('view_maxwidth');
+       $cfg->view_maxwidth(800);
+        $cfg->define('view_maxheight');
+       $cfg->view_maxwidth(600);
+       $cfg->define('disable_rescale');
+       $cfg->disable_rescale(0);
+
        $cfg->define('thumb_pre');
        $cfg->thumb_pre("<div class='thumb'>");
        $cfg->define('thumb_post');
        $cfg->thumb_post("</div>");
        $cfg->define('thumb_pre');
        $cfg->thumb_pre("<div class='thumb'>");
        $cfg->define('thumb_post');
        $cfg->thumb_post("</div>");
+
        $cfg->define('comment_pre');
        $cfg->comment_pre("<div id='comment'>");
        $cfg->define('comment_post');
        $cfg->thumb_post("</div>");
        $cfg->define('comment_pre');
        $cfg->comment_pre("<div id='comment'>");
        $cfg->define('comment_post');
        $cfg->thumb_post("</div>");
+
        $cfg->define('idx_prev_text');
        $cfg->idx_prev_text("&larr; Back");
        $cfg->define('idx_next_text');
        $cfg->idx_next_text("Next &rarr;");
        $cfg->define('idx_ret_text');
        $cfg->idx_ret_text("To index");
        $cfg->define('idx_prev_text');
        $cfg->idx_prev_text("&larr; Back");
        $cfg->define('idx_next_text');
        $cfg->idx_next_text("Next &rarr;");
        $cfg->define('idx_ret_text');
        $cfg->idx_ret_text("To index");
+
        $cfg->define('footer_tag');
        $cfg->define('footer_tag');
-       $cfg->footer_tag('plsgen : Perl Simple Gallery Generator 0.1');
+       $cfg->footer_tag('plsgen : Perl Simple Gallery Generator ' . $version);
 
        $cfg->file($filename) if -f $filename;
        return $cfg;
 
        $cfg->file($filename) if -f $filename;
        return $cfg;
index 0ba6f7884099dc7af194023fb528ca1dcaa5f7f0..7436ef425628c253457df943f24b3e2ce62d9e1d 100644 (file)
@@ -12,11 +12,41 @@ index_tpl_file              = /usr/local/share/plsgen/index.tpl
 css_file               = ../style.css
 navigation_script      = ../nav.js
 
 css_file               = ../style.css
 navigation_script      = ../nav.js
 
+# The default settings makes the 'UP' cursor key navigate to the
+# current index-page when viewing a full display image.
+# Some (many) users dislike this behaviour, so this config
+# option turns the action on or off. Set to 0 to disable up-arrow.
+up_arrow_navigate      = 1
+
 # The layout of the thumbnails in the index. Each row will be wrapped
 # in a <div class='thumnails'>
 rows                   = 4
 columns                        = 5
 
 # The layout of the thumbnails in the index. Each row will be wrapped
 # in a <div class='thumnails'>
 rows                   = 4
 columns                        = 5
 
+# The resizing/scaling of thumbnails and view size images can
+# be run in paralell threads, doing multiple resizes at the
+# same time. On SMP-enabled systems, this may give a gignificant
+# speed boost compared to linear execution. The following option
+# sets the number of resize operations that will run parallel.
+# On simple CPU's this has no gain, so the default is no concurrency.
+concurrent_threads     = 1
+
+# Sizes of the generated images. The following are bounding-box sizes,
+# meaning that an image will be scaled to fit withing the max boundaries,
+# with aspect ratio preserved. The thumb_max* sets the bounding box for all
+# thumbnails, while view_max* sets the display/view size.
+thumb_maxwidth         = 160
+thumb_maxheight                = 120
+view_maxwidth          = 800
+view_maxheight         = 600
+
+# To disable the rescaling of the full-view image completely, set
+# the following option to 1. Thumbnails will still be scaled, and
+# any rotation indicated by EXIF will be done, but the view-size
+# image will be identical to the original. This is useful if
+# all your images are pre-scaled to your liking.
+disable_rescale                = 0
+
 # HTML code to wrap each thumbnail with. The default allows simple
 # styling. If you wish to span this over multiple lines, use the
 # end-of-line continuation mark \
 # HTML code to wrap each thumbnail with. The default allows simple
 # styling. If you wish to span this over multiple lines, use the
 # end-of-line continuation mark \
@@ -29,10 +59,12 @@ thumb_post          = </div>
 comment_pre            = <div id='comment'>
 comment_post           = </div>
 
 comment_pre            = <div id='comment'>
 comment_post           = </div>
 
-
 # Text-strings that can easily be replaced with more complex HTML.
 idx_prev_text          = &larr; Back
 idx_next_text          = Next &rarr;
 idx_ret_text           = To index
 # Text-strings that can easily be replaced with more complex HTML.
 idx_prev_text          = &larr; Back
 idx_next_text          = Next &rarr;
 idx_ret_text           = To index
-footer_tag             = plsgen : Perl Simple Gallery Generator 0.1
+
+# The Album generator tag can be overridden. This is commented
+# out in the sample, but included as an example.
+#footer_tag            = plsgen : Perl Simple Gallery Generator