From: Jon Langseth Date: Tue, 14 Dec 2010 12:44:57 +0000 (+0100) Subject: Added first release code version X-Git-Tag: plsgen-0.1 X-Git-Url: https://git.defcon.no/?a=commitdiff_plain;h=f4f2b8f68d207d3189de1e07b662aaaf4ed5aa8f;p=plsgen Added first release code version --- f4f2b8f68d207d3189de1e07b662aaaf4ed5aa8f diff --git a/README b/README new file mode 100644 index 0000000..5384598 --- /dev/null +++ b/README @@ -0,0 +1,106 @@ +Perl Simple Gallery Generator v 0.1 +============================================== + +Requirements +------------------------ + +Perl modules + * Image::ExifTool + http://search.cpan.org/~exiftool/Image-ExifTool-8.15/ + * AppConfig + http://search.cpan.org/~abw/AppConfig/ + * Getopt::Long (shipped with perl5->) + http://search.cpan.org/~jv/Getopt-Long-2.38/ + +Programs: + * convert from ImageMagick + http://www.imagemagick.org/ + * jhead + http://www.sentex.net/~mwandel/jhead/ + +And, of course you probably want to publish whis on +a Web server. The generated result is static HTML, +so no requirements at all exist in regard to type +and functionality of HTTP daemon. + +Installation +------------------------- + +* Place the navigation JavaScript and the CSS file +somewhere convenient on your Web server. + +* Place the template files (index.tpl, full.tpl) +where You want, I prefer having them located in +/usr/loca/share/plsgen + +* Place the executable script so that execution +is practical. I place it as /usr/local/bin/plsgen so +that I have it in my search path. + +* Take a look at the shipped configuration file. +plsgen looks for a config file as /etc/plsgen.cfg, +as ./plsgen.cfg or ../plgen.cfg relative to where +it is executed. Alternatively, the --config option +allows you to override the default locations. +The shipped config lists all configuration options, +along with their default values (used if no config present). + +Execution / Use +------------------------- + +plsgen is written to be ececuted in a directory filled +with image files, and will create all its data +in this directory. The resulting album will list +all present image files of types JPG, PNG and GIF. +A display-size and thumbnail image will be created +for each image, and will be stored in the sub-directories +view and thumbs (respectively). + +Recognized commandline options are: + --title='Your album title' + Sets the album title. Title will be stored in .title + If no title is given, it will be read from .title, if present + --htmlonly + Add this option to only generate HTML files + No image operations will be performed with this option + --config=/path/to/config + Overrides default config file location. + Default is to look for ./plsgen.cfg, then ../plsgen.cfg + and finally /etc/plsgen.cfg. + --help + Displays a list of available commandline options + +Todo-list +------------------------- +# TODO: filename.txt for file comments +# TODO: Templating of EXIF +# TODO: Priority/sorting of EXIF tags +# TODO: Possibility for hide/show EXIF +# TODO: RSS support? Delegate that to frontend? +# TODO: Save reference to main-index thumbnail. +# TODO: Clear old generated files and meta on regen +# TODO: Use perlmagick et. al instead of convert/jhead.. + +Lisencing +------------------------- +Copyright (c) 2010, Jon Langseth +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL JON LANGSETH BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/full.tpl b/full.tpl new file mode 100644 index 0000000..9e2889a --- /dev/null +++ b/full.tpl @@ -0,0 +1,44 @@ + + + %{title} + %{main_meta} + %{navigation_script} + + +
+ +

%{title}

+ + +
Image %{position}.
+ + + + + +
+ +%{current} + +
+ +
+%{exif} +
+ +
+Generated %{gallery_timestamp} +
+ + +%{navscript} + +
+ + + + diff --git a/index.tpl b/index.tpl new file mode 100644 index 0000000..a3be2bb --- /dev/null +++ b/index.tpl @@ -0,0 +1,27 @@ + + + %{title} + %{main_meta} + %{navigation_script} + + + +

%{title}

+ +%{previous} +  +Page %{position} +  +%{next} + +
+ +%{thumbnails} + +Album generated %{gallery_timestamp} + + +%{navscript} + + + diff --git a/nav.js b/nav.js new file mode 100644 index 0000000..0be7da1 --- /dev/null +++ b/nav.js @@ -0,0 +1,55 @@ +var prev = null; +var next = null; +var index = null; + +var preloaded = []; + +function key_handler ( e ) +{ + var key = (window.event) ? event.keyCode : e.keyCode; + if ( (key == 37) && (prev != null) ) + { + window.location = prev + '.html'; + } + if ( (key == 39) && (next != null) ) + { + window.location = next + '.html'; + } + if (key == 27) window.location = "index.html"; + if ( (key == 38) && (index != null) ) window.location = index; + return; +} +function img_preload ( image ) +{ + var image_thumb = new Image(); + image_thumb.src = 'thumb/' + image; + preloaded.push(image_thumb); + + var image_view = new Image(); + image_view.src = 'view/' + image; + preloaded.push(image_view); +} + +function nav_set_target ( target, direction ) +{ + if ( target ) + { + if ( direction == 0 ) prev = target; + if ( direction == 1 ) next = target; + var img_regx = /.*\.(jpg|JPG|jpeg|JPEG|png|PNG|gif|GIF)$/; + if ( target.match( img_regx ) ) + img_preload( target ); + } +} + +function nav_reg_prev ( target ) +{ nav_set_target(target, 0); } + +function nav_reg_next ( target ) +{ nav_set_target(target, 1); } + +function nav_reg_index( target ) +{ index = target; } + +function nav_reg_onkeypress() +{ document.onkeyup = key_handler; } diff --git a/plsgen b/plsgen new file mode 100755 index 0000000..0f04fb1 --- /dev/null +++ b/plsgen @@ -0,0 +1,373 @@ +#!/usr/bin/perl +use Image::ExifTool; +use POSIX; +use AppConfig; +use Getopt::Long; +use strict; + +# TODO: filename.txt for file comments +# TODO: Templating of EXIF +# TODO: Priority/sorting of EXFI tags +# TODO: Possibility for hide/show EXIF +# TODO: RSS support? Delegate that to frontend? +# TODO: Save reference to main-index thumbnail. +# TODO: Clear old generated files and meta on regen +# TODO: Use perlmagick et. al instead of convert/jhead.. + +# Runtime data +my $title = undef; +my $htmlonly = 0; +my $configfile = undef; +my $halp = undef; + +GetOptions ( + "title=s" => \$title, + "htmlonly!" => \$htmlonly, + "config=s" => \$configfile, + "help" => \$halp +); +if ( $halp ) +{ + print "\nplsgen version 0.1\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 " If no title is given, it will be read from .title, if present\n"; + print " --htmlonly\n"; + print " Add this option to only generate HTML files\n"; + print " No image operations will be performed with this option\n"; + print " --config=/path/to/config\n"; + print " Overrides default config file location.\n"; + print " Default is to look for ./plsgen.cfg, then ../plsgen.cfg\n"; + print " and finally /etc/plsgen.cfg.\n"; + print "\n"; + exit; +} + +# Configuration data +my $config = get_config( $configfile ); +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 $columns = $config->columns; +my $rows = $config->rows; +my $thumb_pre = $config->thumb_pre; +my $thumb_post = $config->thumb_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; + +# Get or save the title, depending.. +if ( (not $title) && ( -f ".title" ) ) +{ + open TF, "<.title"; + $title = ; + chomp($title); + close TF; +} +elsif ( $title ) +{ + open TF, ">.title"; + print TF $title . "\n"; + close TF; +} + +mkdir "thumb"; +mkdir "view"; + +# Glob file names to an array +my @images = glob("*png *.jpg *.JPG *.gif *.GIF"); +# Keep count of total number of images +my $imagecount = $#images; + +my ($current, $previous, $next); +my $indexcount = 1; +my $indexfile; + +my $main_meta = ""; +my $navigation_header = ""; + +my $thumbs = "
"; + +my $indexes = ceil( $imagecount/($rows*$columns) ); +my $gentime = localtime; + +# In groups of N ( X rows x Y colums of index): +# - Step through image array: +for ( my $i = 1; $i <= $imagecount; $i++) +{ + $current = $images[$i-1]; +# - - Previous image is previous location in array, unless cur=first + $previous = $images[$i-2] if $i > 1; + $previous = undef if $i == 1; +# - - Next image is next location in array, unless cur=last. + $next = $images[$i] if $i < ( $imagecount); + $next = undef if $i >= ( $imagecount); + + #Set up text-strings for template replacement + if ( $indexcount == 1 ) { $indexfile = "index.html"; } + else { $indexfile = "index" . $indexcount . ".html"; } + my $navscript = gen_navscript( $previous, $next, $indexfile ); + my $position = $i . " of " . $imagecount; + my $prev_text = ""; + my $next_text = ""; + my $cur_index_text = "" . $idx_ret_text . ""; + my $current_display = "view/" . $current; + + printf ("Processing image %s: %s\n", $position, $current); + +# - - If rotated according to EXIF, do rotation + my $exif = get_exifdata( $current ); + if ( $exif->{'Orientation'} =~ m/rotate/i ) + { + system("jhead -autorot " . $current . ">/dev/null") unless $htmlonly; + } + my $exif_text = get_exifblock($exif); + +# - - 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 full view HTML file + my $cur_html; + open TEMPLATE, "<" . $full_tpl_file or die "UNABLE TO LOAD TEMPLATE $full_tpl_file\n"; + while (