#!/usr/bin/perl # Philip Shuman philip at shuman dot org # http://www.shuman.org/scripts/ # $Id: album.pl,v 1.20 2005/04/04 03:06:51 pshuman Exp $ # # album.pl $version = 'v0.3.7'; # photo album web page generator and photo resizer # # requires ImageMagick's `mogrify` utility, # Image::Size from http://www.blackperl.com/Image::Size/ # and Getopt::Std. # # To install the perl modules, try running: # # perl -MCPAN -e shell # cpan> install Image::Size # cpan> install Getopt::Std # cpan> quit # # Usage: # cd into the directory with your .jpg files. # Run album.pl # Give it the -g 640x480,800x600,1024x768 to create different # scaled images. (without -g will only create thumbnails and html) # Be sure to list your resolutions in ascending order. # # By default, if you run the album.pl again, it will not regenerate the # scaled images if they exist. Give the -f option to force recreation. # # -e will excluding original images from the html. This is useful if your # camera makes images large than what you wnat on your web page. You need # to remove the originals yourself. # # Change thess defauls to your email, name, etc. Any of these values # specified in any of the .albumrc files will take priority. $comment = "Organized with album.pl from shuman.org"; # EXIF comment $name = ""; $mogrify_path = 'mogrify'; #if mogrify isn't in your path, specify the full path $thm_size = "128x96"; $timer = "6"; # number of seconds per image in slideshow $col_width = '6'; # number of thumbnail columns $year = `date '+%Y'`; # This year for copyright date $footer = "Copyright © $year $name All rights reserved. Do not use without permission."; $userHome = $ENV{'HOME'}; print "Checking for $userHome/.albumrc ... "; eval{require "$userHome/.albumrc"}; # load user's Global settings if($@) { print "not found\n"; } else { print "found\n"; } print "Checking for a local .albumrc ... "; eval{require ".albumrc"}; # load album specific settings (overrides above) if($@) { print "not found\n"; } else { print "found\n"; } use Image::Size; use Getopt::Std; sub gen_files { my ($prev_html, $current_html, $current_img, $next_html, $link, $advance, $minus_html, $plus_html, $next_img) = @_; open(FILE, "> $current_html") or die "Can't open: $current_html\n"; print FILE "
| Index | \n"; print FILE "\n"; print FILE " <<\ \;\ \;\n"; print FILE " $state\ \;\ \;\n"; print FILE " >> | \n"; print FILE ""; if ($minus_html ne "" || $plus_html ne "") { print FILE "Zoom: "; } if ($minus_html ne "") { print FILE "(-) "; } if ($plus_html ne "") { print FILE "(+)\n"; } print FILE " | \n"; print FILE "
| \n";
print FILE " \n"; print FILE " $current_img\n"; print FILE " | \n";
print FILE " ||
| $footer\n"; print FILE " | \n"; print FILE "||
| " >> index.html`;
`echo " " >> index.html`; $last_res_index = $#geos; $i_res=0; while ($i_res <= $last_res_index) { #one pass per image size per image my $res = $geos[$i_res]; my $tmp = $file; $tmp =~ s/\.jpg/_$res.jpg/i; if (-f $tmp && !$opt_f) { print " Skipping $tmp\n"; } else { print " Creating $tmp\n"; `cp $file $tmp`; `chmod u+w $tmp`; `$mogrify_path -comment "$comment" -geometry $res -quality 70 $tmp `; } #`echo " $res " >> index.html`; my $prev_name; my $next_name; if ($i > 0) { $prev_name = $files[$i-1]; } else { $prev_name = $files[$last_index]; } chomp($prev_name); if ($i < $last_index) { $next_name = $files[$i+1]; } else { $next_name = $files[0]; } chomp($next_name); $next_img = $next_name; $next_img =~ s/\.jpg/_$res.jpg/i; $next_name =~ s/\.jpg/_$res.html/i; $prev_name =~ s/\.jpg/_$res.html/i; my $htmlfile = $tmp; $htmlfile =~ s/\.jpg/.html/i; my $htmlfile_pause = $htmlfile; $htmlfile_pause =~ s/\.html/_pause.html/i; my $minus = $file; if ($i_res > 0) { $minus =~ s/\.jpg/_$geos[$i_res-1].html/i; } else { $minus = ""; } my $plus = $file; if ($i_res == $last_res_index) { $plus =~ s/\.jpg/.html/i; } else { $plus =~ s/\.jpg/_$geos[$i_res+1].html/i; } if ($i_res == $last_res_index && $opt_e) { $plus = ""; } gen_files($prev_name, $htmlfile, $tmp, $next_name, $htmlfile_pause, 1, $minus, $plus, $next_img); gen_files($prev_name, $htmlfile_pause, $tmp, $next_name, $htmlfile, 0, $minus, $plus, $next_img); `echo " $res " >> index.html`; ++$i_res; } #`echo " $orgsize" >> index.html`; { my $tmp = $file; my $prev_name; my $next_name; if ($i > 0) { $prev_name = $files[$i-1]; } else { $prev_name = $files[$last_index]; } chomp($prev_name); if ($i < $last_index) { $next_name = $files[$i+1]; } else { $next_name = $files[0]; } chomp($next_name); $next_img = $next_name; $next_name =~ s/\.jpg/.html/i; $prev_name =~ s/\.jpg/.html/i; my $htmlfile = $tmp; $htmlfile =~ s/\.jpg/.html/i; my $htmlfile_pause = $htmlfile; $htmlfile_pause =~ s/\.html/_pause.html/i; my $plus = ""; my $minus = $file; if ($i_res > 0) { $minus =~ s/\.jpg/_$geos[$last_res_index].html/i; } else { $minus = ""; } gen_files($prev_name, $htmlfile, $tmp, $next_name, $htmlfile_pause, 1, $minus, $plus, $next_img); gen_files($prev_name, $htmlfile_pause, $tmp, $next_name, $htmlfile, 0, $minus, $plus, $next_img); if (!$opt_e) { `echo " $orgsize " >> index.html`; } } `echo " | " >> index.html`;
$width_counter++;
if ($width_counter >= $col_width) {
`echo "