#!/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 (