#!/usr/bin/perl # # slider # # Take a directory of photos and create a slide show. # # Required support programs: Image::Size # # (C) 2000 Jauder Ho # # 20000203 jauderho [initial whack at the code. will only work with] # [thumbelizer 0.8 and above in thumbelizer_compat mode] # 20000213 jauderho [finished. defaults to standalone mode] # use Image::Size; my (%user,%default,%config); # Adjust to fit to your tastes. You *will* probably want to change these. $viewer = "xv -visual default"; $config{htmlfile} = "index.html"; # name for html file created # Edit these for sure if you don't use --interactive $default{page_heading} = "My Photos"; $default{commentary} = "yes"; # add commentary to each page $default{view_slides} = "yes"; # view the slides # General config vars that are not prompted in --interactive mode. Adjust to # whatever you like. $config{page_bgcolor} = "#ffffff"; # color for the bg of the page $config{color_link} = "#666666"; # color for link in body tag $config{color_alink} = "#ffffff"; # color for alink in body tag $config{color_vlink} = "#999999"; # color for vlink in body tag $config{color_text} = "#000000"; # text for color $config{font} = "helvetica,arial,sans-serif"; # font for page # These are some personal prefs. You may experiment with them if you want $config{fancy_caption} = 1; # Idea originally from kia's site $config{thumbelizer_compat} = 0; # thumbelizer compatability mode # # Do not go any further unless you know what you are doing. You have been # warned appropriately. # $version = "0.4"; # set version number $| = 1; # autoflush output (for progress meter) # Define subroutines sub getPrefs; sub processPrefs; sub processImages; sub switchCheck; sub printUsage; sub printVersion; sub printHTML; # Start your engines... switchCheck; # Check ARGV printVersion; # Print version if ($config{thumbelizer_compat} == 0) { $default{sourcedir} = "."; # picture dir } else { $default{sourcedir} = "../images/1"; # picture dir $default{orgsourcedir} = "../originals"; $default{thumbelizerdir}= ".."; } # Figure out if we are in interactive mode or use the default prefs instead. ($mode_interactive) ? getPrefs : (%user = %default); processPrefs; # Do some post processing on the prefs processImages; printHTML; # The End # Sets user prefs sub getPrefs { print "\n"; # Image source directory. Remember you are creating pages in the local # directory and links relative to the current directory so no silly # business with full paths. print "Image source directory [$default{sourcedir}]: "; $user{sourcedir} = ; # Page heading. We are also going to use this to print "Caption [$default{page_heading}]: "; $user{page_heading} = ; # Add comments to each slide print "Add commentary [$default{commentary}]: "; $user{commentary} = ; # View slides? print "View slides before commenting [$default{view_slides}]: "; $user{view_slides} = ; # Fill in the blanks. for (keys %default) { chomp($user{$_}); $user{$_} = $default{$_} if ($user{$_} =~ /^$/); } # Start doing sanity checks and some preprocessing # Make sure that the input directory exists die "ERROR: Source directory does not exist.\n" unless (-d $user{sourcedir}); print "\n"; } sub processPrefs { # Make sure the directory exists or stop right away die "ERROR: $user{sourcedir} does not exist.\n" unless (-d $user{sourcedir}); # Figure out the set name to put stuff in $setname = $user{page_heading}; $setname = lc($setname); $setname =~ s/\W//g; } sub processImages { my $count; my $image; $count = 0; # Locate all the binary files, presumably image files. for $image (<$user{sourcedir}/*>) { if (-B $image && -f $image) { $images[$count]{file} = $image; # Figure out the size of the image ($images[$count]{width}, $images[$count]{height}) = imgsize($image); # Record the commentary if ($user{commentary} =~ /^y/i) { my $comment; print "Comment for $image: "; # Check if we are going to view the pics using # the viewer program. system("$viewer $image &") if ($user{view_slides} =~ /^y/i); $comment = ; chomp($comment); $images[$count]{comment} = $comment; } ++$count; } } } sub printHTML { print "\n"; print "Creating html file "; for (0 .. $#images) { my ($file,$pfile,$nfile); my $image; $image = $images[$_]; $file = "$_" . ".html"; # Set the name of the file # Make sure that we generate the right links if ($_ == 0) { $pfile = "$#images" . ".html"; if ($#images == 0) { $nfile = "0" . ".html"; } else { $nfile = ($_ + 1) . ".html"; } } elsif ($_ == $#images) { $pfile = ($_ - 1) . ".html"; $nfile = "0" . ".html"; } else { $pfile = ($_ - 1) . ".html"; $nfile = ($_ + 1) . ".html"; } open(HTML,"> $file") or die "ERROR: Cannot open file $file for writing.\n"; # Write header information print HTML "\n", "\n\n", "\n"; # Print the title print HTML "\t", "$user{page_heading} ", "[", ($_ + 1), "/", ($#images + 1), "]", "\n"; # Write the rest of the header print HTML "\t\n", "\n\n", "\n\n", "
\n\n"; # Do we want a fancy heading? If so, uppercase # $user{page_heading} if ($config{fancy_caption} == 1) { my @caption; my ($string) = uc($user{page_heading}); (@caption) = split(//,$string), print HTML "
", join("    ",@caption), "\n


\n"; } else { print HTML "

$user{page_heading}

\n", "$user{page_desc}

\n"; } # Are we in thumbelizer compat mode? if ($config{thumbelizer_compat} == 1) { print HTML "", "index

\n"; } # Print left nav arrows print HTML "<<<\n"; print HTML "    \n"; # Print the pic!!! print HTML "", "{file}\" ", "align=\"middle\" border=\"1\" ", "width=\"$image->{width}\" ", "height=\"$image->{height}\" ", "alt=\"image $image->{file}\">", "\n"; # Print right nav arrows print HTML "    \n"; print HTML ">>>\n"; if ($image->{comment}) { print HTML "

$image->{comment}

\n"; } else { print HTML "

"; } # Write credit info print HTML "\n

Generated by ", "", "slider $version"; # Write footer information print HTML "

\n\n", "\n\n", "\n"; close(HTML); # Progress meter ... print "."; } # Remove an old index.html if it already exists and create the entry # point for the slide show. unlink("index.html") if (-f "index.html"); symlink("0.html","index.html"); print " Done\n"; } # Print program usage sub printUsage { print "Usage: slider [OPTION]\n\n", "\t-i, --interactive\tsome config settings prompted\n", "\t-d, --default\t\tdefault mode, uses defaults within file\n", "\t-h, --help\t\tdisplay help (this menu) and exit\n", "\t-v, --version\t\toutput version and exit\n\n"; } # Print program name and version number sub printVersion { print "slider $version\n"; } sub switchCheck { # Make sure we are passed decent arguments unless ($#ARGV == 0) { printUsage; exit; } $_ = $ARGV[0]; if (/^-{1,2}i/) { $mode_interactive = 1; } elsif (/^-{1,2}d/) { $mode_interactive = 0; } elsif (/^-{1,2}v/) { printVersion; exit; } else { printUsage; exit; } }