#! /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; # args? if ($#ARGV == -1) { print "Usage webphoto.pl -o|-n\n"; print " (-o = overwrite; -n = no overwrite)\n"; } # 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. "; print "I refuse to overwrite and make an error you will regret later.\n"; print "You will need to delete this file manually and run me again.\n\n"; exit; } # check the thumbnails directory if (-e "thumbnails") { print "\nthumbnails directory already exists. "; print "I refuse to overwrite and make an error you will regret later.\n"; print "You will need to delete this directory manually and run me again.\n\n"; exit; } else { system "mkdir thumbnails"; } # check the fullsize directory if (-e "fullsize") { print "\nfullsize directory already exists. "; print "I refuse to overwrite and make an error you will regret later.\n"; print "You will need to delete this directory manually and run me again.\n\n"; 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 *.jpg *.gif`; $numfiles = @files; # create thumbnails $imgcount = 1; foreach $imgfile (@files) { # how far have we gotten? print "$imgcount of $numfiles\n"; $imgcount++; # get the basename of the image file $basefile = basename($imgfile); chop $basefile; # try to nconvert just with the -info option to get file properties @info = `nconvert -quiet -info $basefile`; # 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) { $scale = 150 / $wid * 100 } else { $scale = 150 / $ht * 100 } # rescale to create the thumbnail at a max if 150 pixels system "nconvert -quiet -resize $scale% $scale% -o thumbnails/$basefile $basefile"; # copy the original file to the fullsize directory system "cp $basefile fullsize/$basefile"; } # mangle the list of files @filez = (); foreach $file (@files) { $filename = basename($file); chomp $filename; push @filez, $filename; } # get directory name $dirname = basename(`pwd`); chomp $dirname; # make a "pages" dir for individual pages if (! -e "pages") { system("mkdir pages"); } # start writing the index page open(MASTERPAGE, '>index.html'); print MASTERPAGE "\n"; print MASTERPAGE "
\n"; print MASTERPAGE "