The method for setting up an automed system for creating the picture galleries have been purposily kept simple. The photos are transferred by the system described in the technical document Picture_Transfer.txt, found at http://www3.isrl.uiuc.edu/~webvibe/doc/Picture_Transfer.txt. Then this script is run as a cron task. It looks at the /home/TeleNature/public_html/photo directory, and sees if there has been any change from the saved file that contains the old file information. If it does, it generates a set of new thumbnails and a new page. There are some drawbacks, but the system has been kept purposely simple since it was mainly to demonstrate that such a system was feasible. Setup The setup directions are as follows. 1. Copy the below script, and change the various paths to how the system is set up. 2. Create the directory where the html page will be generated, and create a directory named thumbnails. 3. Set up a cron job that runs every few seconds or minutes. General A more overall view follows My directory structure and essential files currently looks like this ... The script resides in /home/phototrans/html_create.plx The photo directory is /home/TeleNature/public_html/photos/ /home/TeleNature/public_html/photos/ls.txt /home/TeleNature/public_html/photos/thumbnails/ The cron job runs from the phototrans account, which has write access to the /home/TeleNature/public_html/photos account. Script How the script essentially works is in a couple of steps: 1. It performs an ls -l on the photo directory and compares it to a stored file called "ls.txt" which has the ls -l output of the last time the script was run. If it's different, it goes to step 2, otherwise it just exists. 2. It opens a file in the photo directory called "index.html" and starts writing out a simple html file to it, starting with the headers and then creating a 5 x infinity table. 3. It scans through the ls listing and parses out the names of the files. If it ends in ".html" or ".txt" or is the name "thumbnails" it is ignored. For all others, it does the following: i. Runs the convert program of ImageMagick to create a thumbnail of it, a smaller, lower quality copy of the image. ii. Writes a line to the index.html that adds a cell that has an link using the thumbnail image as well was a link with the file name text. 4. After running through all the files in the ls output, it writes the closing html tages to the "index.html" 5. Finally, it writes out the current ls output to the "ls.txt" file. Jon Gorman Version: $Revision: 1.3 $ Created: 1/11/2004 Last Modified 1/11/2004 ------------------------------------------------------------------------------- The script as of 1/11/2004 ------------------------------------------------------------------------------- #!/usr/bin/perl #So the question is how to tell if there is a change... #easiest way seems to me to do a ls -l, then compare that to a file #already in existance... #Could probably make this a shell script #This is the path to the photo directory.... $photo_dir = "/home/TeleNature/public_html/photos"; $photo_ls = "/home/TeleNature/public_html/photos/ls.txt"; $ls_detailed = `ls -l $photo_dir`; $ls = `ls -1 $photo_dir`; $difference = `echo \"$ls_detailed\" | diff $photo_ls - `; if ($difference ne "") { #ok, for now, we just recreate the thumbnails directory... #not the best way to do this I realize... #system("rm ${photo_dir}/thumbnails/*"); #now I replace the html file and the ls.txt file" open(INDEXFILE, "> $photo_dir/index.html") or die ("Can't open file"); #probably better way to do this print INDEXFILE ("\n\t\n\t\tPhotographs\n\t\n\t\n"); print INDEXFILE ("\n"); print INDEXFILE ("\n"); #Now I want to process $ls line by line...so ... @lines = split(/\n/,$ls); $count = 0; foreach $line (@lines) { #if not ending with html or text, I'll assume it is a photo chomp $line; if ($count == 9) { print INDEXFILE ("\n\n"); $count = 0; } else {$count++;} #need to check the regex end of line symbol... if (!(($line =~ /\.html/) or ($line =~ /\.txt/) or ($line eq "thumbnails"))) { # here we should also make a folder that contains the #thumbnail images, be much quicker to load up... #although we should also modify it so there # are "pages" somehow.... system("convert -size 150x150 ${photo_dir}/${line} -resize 150x150 +profile \"*\" ${photo_dir}/thumbnails/th_${line}"); print INDEXFILE ("\n"); } } print INDEXFILE ("\n"); print INDEXFILE ("
$line
\n"); print INDEXFILE ("\n\t\n"); close INDEXFILE; #This should write out to the ls file, replacing it... #hack, fix later system("echo \"$ls_detailed\" > $photo_dir/ls.txt"); #Should make the source look better as well as the table... }