X-Git-Url: https://git.defcon.no/?p=plsgen;a=blobdiff_plain;f=plsgen;h=f5876d42bca506c03faeb3c0ec2423407af18fcf;hp=0f04fb11f9847cf69c04a7f8e9e7c2147672f3d0;hb=68c39fb44a748326e82293210c9cc48d85fe874b;hpb=f4f2b8f68d207d3189de1e07b662aaaf4ed5aa8f diff --git a/plsgen b/plsgen index 0f04fb1..f5876d4 100755 --- a/plsgen +++ b/plsgen @@ -5,12 +5,10 @@ use AppConfig; use Getopt::Long; use strict; -# TODO: filename.txt for file comments # TODO: Templating of EXIF -# TODO: Priority/sorting of EXFI tags +# 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.. @@ -19,10 +17,13 @@ my $title = undef; my $htmlonly = 0; my $configfile = undef; my $halp = undef; +my $album_comment = undef; +my $doexif = 1; GetOptions ( "title=s" => \$title, "htmlonly!" => \$htmlonly, + "exif!" => \$doexif, "config=s" => \$configfile, "help" => \$halp ); @@ -36,6 +37,8 @@ if ( $halp ) 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 " --noexif\n"; + print " Forces EXIF data block not to be written to HTML output\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"; @@ -54,6 +57,8 @@ my $columns = $config->columns; my $rows = $config->rows; my $thumb_pre = $config->thumb_pre; my $thumb_post = $config->thumb_post; +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; @@ -74,13 +79,21 @@ elsif ( $title ) close TF; } +# Get the album comment, if available +if ( -f "comment.txt" ) +{ + open CF, ") { $album_comment .= $_; } + close CF; +} + 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 $imagecount = $#images+1; my ($current, $previous, $next); my $indexcount = 1; @@ -116,6 +129,19 @@ for ( my $i = 1; $i <= $imagecount; $i++) my $cur_index_text = "" . $idx_ret_text . ""; my $current_display = "view/" . $current; + # Check for, and load comment from FILENAME.txt here.. + my $comment = undef; + if ( -f $current . ".txt" ) + { + open CF, "<" . $current . ".txt"; + while () { $comment .= $_; } + close CF; + } + if ( $comment ) + { + $comment = $comment_pre . $comment . $comment_post; + } + printf ("Processing image %s: %s\n", $position, $current); # - - If rotated according to EXIF, do rotation @@ -124,13 +150,20 @@ for ( my $i = 1; $i <= $imagecount; $i++) { system("jhead -autorot " . $current . ">/dev/null") unless $htmlonly; } - my $exif_text = get_exifblock($exif); + 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; +# - - Save a reference to the "primary image" + if ( not -f ".indeximage" ) + { + open IM, ">.indeximage"; + print IM $current; + close IM; + } # - - Create full view HTML file my $cur_html; open TEMPLATE, "<" . $full_tpl_file or die "UNABLE TO LOAD TEMPLATE $full_tpl_file\n"; @@ -149,6 +182,7 @@ for ( my $i = 1; $i <= $imagecount; $i++) $_ =~ s/%\{position\}/$position/; $_ =~ s/%\{current\}/$current/; $_ =~ s/%\{current_display\}/$current_display/; + $_ =~ s/%\{comment\}/$comment/; $_ =~ s/%\{exif\}/$exif_text/; $_ =~ s/%\{gallery_timestamp\}/$gentime/; $_ =~ s/%\{navscript\}/$navscript/; @@ -166,7 +200,7 @@ for ( my $i = 1; $i <= $imagecount; $i++) { $thumbs .= ""; # - - On each Y, terminate index file/group: - make_index( $index_tpl_file, $indexcount, $indexes, $thumbs); + make_index( $index_tpl_file, $indexcount, $indexes, $thumbs, $album_comment ); $thumbs = "
"; $indexcount++; } @@ -177,7 +211,7 @@ for ( my $i = 1; $i <= $imagecount; $i++) } } $thumbs .= "
"; -make_index( $index_tpl_file, $indexcount, $indexes, $thumbs); +make_index( $index_tpl_file, $indexcount, $indexes, $thumbs, $album_comment ); # Done. @@ -188,6 +222,7 @@ sub make_index my $idxcount = shift; my $lastidx = shift; my $thumbs = shift; + my $comment = shift; my $gentime = localtime; my $html; @@ -216,6 +251,11 @@ sub make_index $next_text = "" . $idx_next_text . ""; } + if ( $comment ) + { + $comment = $comment_pre . $comment . $comment_post; + } + my $position = $indexcount . " of " . $lastidx; my $navscript = gen_navscript( $prev_file, $next_file ); @@ -225,6 +265,7 @@ sub make_index $_ =~ s/%\{previous\}/$prev_text/; $_ =~ s/%\{next\}/$next_text/; $_ =~ s/%\{title\}/$title/; + $_ =~ s/%\{comment\}/$comment/; $_ =~ s/%\{position\}/$position/; $_ =~ s/%\{main_meta\}/$main_meta/; $_ =~ s/%\{navigation_script\}/$navigation_header/; @@ -251,7 +292,7 @@ sub get_exifdata ($) my $info = $exifTool->ImageInfo($image); $exif->{'Make'} = $info->{'Make'}; $exif->{'Model'} = $info->{'Model'}; - #$exif->{'Orientation'} = $info->{'Orientation'}; + $exif->{'Orientation'} = $info->{'Orientation'}; $exif->{'ExposureTime'} = $info->{'ExposureTime'}; $exif->{'FNumber'} = $info->{'FNumber'}; $exif->{'ISO'} = $info->{'ISO'}; @@ -277,6 +318,7 @@ sub get_exifblock my $flipflop = 0; foreach my $tag ( keys %$exif ) { + next if $tag =~ m/Orientation/; my $val = $exif->{$tag}; next unless $val; $block .= "" if $flipflop; @@ -354,6 +396,10 @@ sub get_config $cfg->thumb_pre("
"); $cfg->define('thumb_post'); $cfg->thumb_post("
"); + $cfg->define('comment_pre'); + $cfg->comment_pre("
"); + $cfg->define('comment_post'); + $cfg->thumb_post("
"); $cfg->define('idx_prev_text'); $cfg->idx_prev_text("← Back"); $cfg->define('idx_next_text');