#!/usr/bin/perl use Image::ExifTool; use POSIX; use AppConfig; use Getopt::Long; use threads; use threads::shared; use strict; # DONE: Removed some default values in config, allowing empty options # 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.. # BUG: The naive handling of filenames breaks on special characters my $version = "0.3"; # Runtime data my $title = undef; my $htmlonly = 0; my $configfile = undef; my $halp = undef; my $album_comment = undef; my $doexif = 1; my $threadcounter = 0; share ( $threadcounter ); GetOptions ( "title=s" => \$title, "htmlonly!" => \$htmlonly, "exif!" => \$doexif, "config=s" => \$configfile, "help" => \$halp ); if ( $halp ) { 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 " 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 " --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"; 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 $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 $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 $concurrent = $config->concurrent_threads; # 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; } # 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+1; 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 = "Previous image"; my $next_text = "Next image"; my $cur_index_text = "" . $idx_ret_text . ""; 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" ) { 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 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) if $doexif; ## - - 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" ) { 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"; while (