#! /usr/bin/perl -w #----------------------------------------------------------- # creates a web photo album from all *.jpg and *.gif files in current dir # creates a directory called pages containing the pages for each individual image # creates a file called index.html (the navigation page) # creates a dir called fullsize containing the images # creates a dir called thumbnails containing thumbnail images # you must have nconvert installed. Get from # http://www.xnview.com/ #----------------------------------------------------------- # to make getting the basename of the dir easy use File::Basename; use File::Copy; use Cwd; $command = basename ($0); # args? if ($#ARGV == -1) { print "Usage $command -on srcdir}\n"; print " (-o = overwrite; -n = no overwrite)\n"; exit; } # source dir? if ($#ARGV == 1) { if (-d $ARGV[1]) { $srcdir = "$ARGV[1]/"; } } else { $srcdir = ""; } # convert backslashes to forward slashes $srcdir =~ s|\/\/|\/|; # overwrite without complaining? if ($ARGV[0] eq "-o") { if (! -e "thumbnails") { system "mkdir thumbnails"; } if (! -e "fullsize") { system "mkdir fullsize"; } } elsif ($ARGV[0] eq "-n") { # check the index.html page if (-e "index.html") { print "\nindex.html already exists. \n"; &error; exit; } # check the thumbnails directory if (-e "thumbnails") { print "\nthumbnails directory already exists. \n"; &error; exit; } else { system "mkdir thumbnails"; } # check the fullsize directory if (-e "fullsize") { print "\nfullsize directory already exists. \n"; &error; exit; } else { system "mkdir fullsize"; } } else { print "Usage webphoto.pl -o|-n\n"; print " (-o = overwrite; -n = no overwrite)\n"; exit; } # list of jpeg and gif files in current dir @files = `ls $srcdir*.[Jj][Pp][Gg] $srcdir*.gif`; $numfiles = @files; # copy the perl file to this directory copy ( "$0", "webphoto.pl" ); # create thumbnails $imgcount = 1; foreach $imgfile (@files) { # how far have we gotten? print "$imgcount of $numfiles... "; $imgcount++; # get the basename of the image file chomp $imgfile; ($base, $path, $type) = fileparse("$imgfile", qr{\..*}); $basefile = "$base$type"; $srcfile = "$srcdir/$basefile"; # try to nconvert just with the -info option to get file properties @info = `nconvert -quiet -info $srcfile`; # did I find the word "Failed"? means the image has problems @match = grep(/.*Failed.*/, @info ); $count = @match; if ($count == 1) { print "Error in image file, or is not an image.\n"; exit; } # get the width & height of the image for resizing @width = split (/ */, $info[4]); $wid = ("$width[3]"); chop $wid; @height = split (/ */, $info[5]); $ht = ("$height[3]"); chop $ht; # I want the maximum thumbnail dimension to be 150 pixels if ($wid > $ht) { $thumbscale = 150 / $wid * 100; $maxdim = $wid; } else { $thumbscale = 150 / $ht * 100; $maxdim = $ht; } # rescale to create the thumbnail at a max if 150 pixels print "\nmaking thumbnail ($srcfile => thumbnails/$basefile)...\n"; system "nconvert -quiet -resize $thumbscale% $thumbscale% -o thumbnails/$basefile $srcfile"; # is the original image larger than 800 pixels wide or high? If so, rescale if ($maxdim > 800) { if ($wid > $ht) { print "making rescaled image ($srcfile => fullsize/$basefile)... \n"; $fullscale = 800 / $wid * 100; system "nconvert -quiet -resize $fullscale% $fullscale% -o fullsize/$basefile $srcfile"; } elsif ($ht > $wid) { print "making rescaled image ($srcfile => fullsize/$basefile)... \n"; $fullscale = 800 / $ht * 100; system "nconvert -quiet -resize $fullscale% $fullscale% -o fullsize/$basefile $srcfile"; } } else { print "copying image ... \n"; system "cp $basefile fullsize"; } } # mangle the list of files @filez = (); foreach $file (@files) { chomp $file; ($base, $path, $type) = fileparse("$file", qr{\..*}); $filename = "$base$type"; push @filez, $filename; } # get directory name $pwd = getcwd; $dirname = basename( $pwd ); chomp $dirname; # make a "pages" dir for individual pages if (! -e "pages") { system("mkdir pages"); } # start writing the index page open(SLIDESHOWPAGE, '>index_slideshow.html'); print SLIDESHOWPAGE "\n"; print SLIDESHOWPAGE "
\n"; print SLIDESHOWPAGE "Click on a thumbnail to start the photo album.
\n"; print SLIDESHOWPAGE "| ";
$url1 = " | \n";
$url = "$url0\n $url1\n";
($soundfile = $file) =~ s|[Jj][Pp][Gg]|wav| ;
$url_java0 = "";
$url_java1 = "