#!/usr/bin/perl ############################################################# #update!!! this version now includes better error messages, with an option to have either technical error messages #or nice ones for non-sysadmins. With the non-technical error message is a mailto link so the viewer can email you the #problem info--already filled out in the email for them # --I am considering writing to a log file instead, but that could needlessly complicate matters--once the program is up #and running and debugged, it really should not generate any more errors # # # # photoview Version 1.55a# #automatic thumbnail photo gallery creation and viewing of images at different resolutions #works with any image format #Version Date: 12 December 2000 #works with picsize_finder version 1.31 or higher #Copyright 2000 by Michael K. Goode# #This script is free for use, distribution, and modification# #The only right I reserve is this header must remain intact, as long as the program# #is used for its original purpose (displaying a thumbnail gallery and pictures at different resolutions).# #This header may be removed, if, and only if, a portion of the code is used in a program that does not# #fulfill either of the two functions of this program# #The home of this script: http://www.mikegoode.com/web/scripts/# #please check there for any updates or upgrades or bug fixes and for help files# #my email address: mike@mikegoode.com# #if you have any good changes or additions, please email them to me,# #and I will add them to the picvu program or add new versions of the program# #to my website and credit you.# ## #I am not responsible for any damage resulting from the use of this program# #and I make no guarentees about its performance, specific or implied# #I am also not able to help anyone with support, other than # #by providing some basic help info on my website.# ############################################################# # YOU CAN CHANGE ANYTHING BELOW THIS POINT TO YOUR HEART'S CONTENT# ############################################################# #all the images in a certain gallery must be in the same directory #This program requires a text file #be present in the same directory as the full-size photos and the #thumbnails. The gallery.txt file should be in this format: # thumbnail(tab)width of thumb(tab)height of thumb(tab) # full-size(tab)width (pixels) of full size(tab)height (pixels) of full size(tab)title [new line] # thumbnail2(tab)width of thumb(tab)height of thumb(tab)full-size2(tab) # width (pixels) of full size(tab)height (pixels) of full size(tab)title [new line] . . . etc. #include the three letter filename ending (.jpg) of the file!!! #Each entry should be separated by one tab, and there #should be a new line for each different picture. #the thumbnails do not need to have the same name as the big image files #to have this gallery.txt file automatically created, go to my script archive and download picsize_finder.pl # #When linking to a particular gallery, make the hyperlink like this: #"http://www.mikegoode.com/cgi-#bin/photoview.pl?http://www.mikegoode.com/photo/gallery/mike3&Photo=Gallery=3&gallery" #where you link to the program's absolute url, and after the question mark have the absolute url of the directory #of the thumbnail gallery. Make sure to NOT include the trailing slash after the directory title. #And then have an '&' and the title of the gallery. #also, make sure to have an equals sign [=] in place of any spaces in the title section of the hyperlink to this program #the spaces will be put back later. Without changing the code of this program, the title #can be up to four words long #also, the links to the thumbnail page must end in '&gallery' --that is how the program decides whether to run #the thumbnail or pictureview subroutine. ################################################################ #version info: this version (1.55) allows infinitely long gallery titles. That is the only upgrade from v1.51 ######################################### #General and gallery configuration section ################################### use strict; my($text_file) = 'cheese.txt'; #this is the file name of the text file that has all the information in it my($absolut_directory) = '/data/domains/mikegoode.com/public_html/photo/gallery'; #this is the absolute path to your base photo gallery directory - leave the trailing slash off my($program) = 'http://www.mikegoode.com/cgi-bin/photoview.pl'; #this is the URL of this program my($gallery_bgcolor) = "ECECEC"; #the background color of the gallery in hexadecimal notation (put "FFFFFF" for white) my($thumb_border) = "0"; #the size of border you want on the thumbnails, in pixels. "0" for no border ############################################# #Configuration section for Image Viewer section (not thumbnails) ############################################# my($title) = "GodotWEB Photo Gallery"; # This is the title of your page my($bgcolor) = "ececec"; # This is the background color for the pages this script creates #in hexadecimal. put "FFFFFF" for white my($border) = "0"; # This is the size of the border you want around the large images. "0" for no border my($small_multiplier) = .25; my($medium_multiplier) = .50; my($large_multiplier) = .75; #these are the proportions of the full size image #that you will multiply the dimensions by to get #the different size images #use decimals, and not fractions my($default_picture_size) = 'medium'; #set the default picture size to 'small' , 'medium' , 'large' , or 'full' ###################################### ###Configuration section for &error subroutine ###################################### my($email) = 'mike@mikegoode.com'; #the sysadmin's email (yours, I assume) my($debuggy) = '0'; #1 if you are debugging the program, otherwise 0 ############################################## ##Below here all you need to edit is the html in the header and footer for ##both the thumbnail gallery and image viewer subroutines ######################################## #print "Content-type: text/html\n\n"; #this prints out the html header before anything else, so #any errors will be displayed properly if ($ENV{'QUERY_STRING'} eq ""){ error("no info in query string!!!"); } my($directory_and_title) = "$ENV{'QUERY_STRING'}"; my(@test2) = split(/&/, $directory_and_title); my($test3) = pop(@test2); unless ($test3 eq 'gallery'){&pictureview} ######################################## #predeclare thumbnail gallery variables my(@directory_plus_title, $directory, $gallery_title, $return, @directory, $gallery_directory, @ga_title, $gal_footer, $gal_header, $this_line, @pic_info, $thumbnail, $x, $y, $big_pic, $width, $height, $pic_title); ################################################# ##this may seem confusing, but it is basically checking to see if the program was called ##to display a thumbnail gallery or one picture. If the latter, it goes to the pictureview subroutine. #it gets the info from the query string, and if it finds 'gallery' on the end, it runs the thumbnail routine #it then stores the query string as a scalar #this next section gets the gallery directory and title from the query string #and puts together $return #it will be used to form the $return_string for future versions @directory_plus_title = split(/&/, $directory_and_title); $directory = shift(@directory_plus_title); $gallery_title = shift(@directory_plus_title); $return = "$program" . '?' . "$directory" . '&' . "$gallery_title"; #this takes the query string info, and parses the directory and #gallery title info into two different variables, @directory = split(/\//, $directory); $gallery_directory = pop(@directory); @ga_title = split(/=/, $gallery_title); $gallery_title = join(" ", @ga_title); #this puts the gallery title in a nice-looking string, eliminating the equals signs ######################################### #thumbnail gallery header and footer html ######################################## #just change the html to edit the parts of the thumbnail gallery above (header) and #below (footer) the photos ##no backslash is needed before quotes --just enter normal html between the ##and comments, and the same with the header. $gal_footer = <<"BOB";


Navigate GodotWeb

Home > Photo > Photo Galleries > $gallery_title





(All photos © 1999 by Michael Goode. Note: You may copy the eletronic versions of these photos for your own personal use. they may be displayed on any not for profit website, as long as you credit me and link to this site, and do not use them in any way that implies that I have any connection at all to you or your website or that I endorse any goals, aims, ideas, or beliefs of you or your organization. You may not display them on any website that includes pornographic or violent content. You may not charge for them, alter them or disseminate them by any non-electronic method, such as printing. I reserve all rights not explicitly given up by this disclaimer. If you want to include these photos on your website, I would ask you to please ask me, just as a matter of courtesy.)




BOB 1; #######header####### $gal_header = <<"FOB"; $gallery_title

$gallery_title

Photographs by Michael Goode


Click on an Image to View Larger Versions


FOB 1; ############################################## print "Content-type: text/html\n\n"; print "$gal_header"; chdir("$absolut_directory/$gallery_directory") || error("cannot chdir to $absolut_directory/$gallery_directory", '1'); open(LISTFILE, "<$text_file") || error("The file $text_file in directory $absolut_directory/$gallery_directory could not be found\n", '1'); #this opens the text file for reading or kills the program and displays #an error message if the file cannot be opened. #the while loop prints out the thumbnails while() { $this_line = $_; chomp($this_line); (@pic_info) = split(/\t/, $this_line); #this parses each line in the gallery.txt file into a list called @pic_info #the following section parses the thumbnail and full-sized image filenames (and title of pic) #and sizes into their respective variables, and if no title exists, makes the title "Untitled" $thumbnail = shift(@pic_info); $x = shift(@pic_info); $y = shift(@pic_info); $big_pic = shift(@pic_info); $width = shift(@pic_info); $height = shift(@pic_info); $pic_title = pop(@pic_info); if($pic_title eq ""){$pic_title = 'Untitled'} print "


$pic_title

"; #this is the html printed out with each image #edit the html to your delight, but remember the \ before every " #also, do not change the variables } close(LISTFILE); print "$gal_footer"; exit; ######################################## #This rest of the program is the image viewer subroutine. # #Some elements of it have to be edited. # ######################################## ####You do NOT need to change anything in this next block #### ######################################## sub pictureview { #predeclare variables with my my($lots_of_info, @a, $return, $return_b, @information, $file, $picture_width, $picture_height, $picture_size, @dir_list, $i, $gallery_num, $this_line, @pic_info, $big_pic, $pic_title, $picture_height_new, $picture_width_new); if ($ENV{'QUERY_STRING'} eq ""){ error("no info in query string!!"); #exits if no info in query string } else { $lots_of_info = "$ENV{'QUERY_STRING'}"; ####new code #this section of code gets the $return string from the query string, so that the pictureview #page can link back to the thumbnail gallery page. @a = split(/\|/, $lots_of_info); $lots_of_info = @a[0]; $return = @a[1]; $return_b = $return . '&gallery'; ### (@information) = split(/&/, $lots_of_info); $file=@information[0]; $picture_width=@information[1]; $picture_height=@information[2]; $picture_size=@information[3]; #the thumbnail subroutine sends the image size to this subprogram in the query string #the above lines get the picture info from query string #This next line of code gets the picture title and gallery number from the $file variable, #originally from the query string, for use in the while loop below @dir_list = split(/\//, $file); $i = pop(@dir_list); $gallery_num = pop(@dir_list); chdir("$absolut_directory/$gallery_num/") || error("cannot chdir to $absolut_directory/$gallery_num/"); open(LISTFILE, "<$text_file") || error("The file $text_file could not be opened in directory $absolut_directory/$gallery_num/ \n."); #this opens the text file for reading or kills the program and displays #an error message if the file cannot be opened ######this loop searches through the gallery.txt file to find the title of the image to display#### while() { $this_line = $_; chomp($this_line); (@pic_info) = split(/\t/, $this_line); $big_pic = @pic_info[3]; if($big_pic eq $i){ $pic_title = pop(@pic_info); if($pic_title =~ /\d\d\d/){$pic_title = 'Untitled'} #this checks to see if there is a title in the gallery.txt file; #if there isn't, it will find a digit, and will put 'untitled' as the title } } close(LISTFILE); #this next block checks to see the size of the picture that should be displayed #and then adjusts the size of the picture accordingly if($picture_size eq 'small') { $picture_height_new = $picture_height * $small_multiplier; $picture_width_new = $picture_width * $small_multiplier; } elsif($picture_size eq 'medium') { $picture_height_new = $picture_height * $medium_multiplier; $picture_width_new = $picture_width * $medium_multiplier; } elsif($picture_size eq 'large') { $picture_height_new = $picture_height * $large_multiplier; $picture_width_new = $picture_width * $large_multiplier; } elsif($picture_size eq 'full') { $picture_height_new = $picture_height; $picture_width_new = $picture_width; } ##if anything else ends up in the variable $picture_size ##this makes the program just display the full size image ##to prevent it from displaying any weird things ##or crashing or displaying nothing at all; else{ $picture_height_new = ""; $picture_width_new = ""; } } ################################ ###You do need to change info in this next block.### ################################ ########################## # Display requested picture ########################## #edit the html below to your delight to edit the look of the html page displayed with the image #just input plain html, except there must be a '\' (backslash) before every quote # also, do not edit the variables ########################## print "Content-type: text/html\n\n"; print "$title: $pic_title\n"; print "\n"; print"

$pic_title

by Michael Goode

"; print "



\n"; print "

View at Different Resolutions\n

"; print ""; print ""; print ""; print ""; print ""; print "
"; print "Small"; print "Medium"; print "Large"; print "Full Size

"; print "Return to Photo Gallery

"; print "Return to GodotWEB

"; print "\n"; exit; } exit; ####################### #subroutine &error -- displays error messages with html headers and option to display a non-sysadmin user friendly #error message with a link to email the sysadmin, with all the pertinent error info already in the subject of #the email ##################################### #error("cannot chdir"); call this subroutine like this #if the html header has already been printed, call it like this: error("cannot chdir", 1); sub error{ #predeclare all variables with my my($error, $error_message, $debug, $webmaster, $a); my(@time) = localtime; my($time) = "@time[2]" . ':' . "@time[1]" . ':' . "@time[0]" . ' on the ' . "@time[7]". 'th day of this year'; $error = shift(@_); $a = pop(@_); #$a is to determine if an html header has already been printed. If it has, when calling the subroutine, #have '1' as the rightmost part of the &error(list) --if not, then don't put anything there ####################################### $webmaster = $email; #to use this subroutine outside of this program, explicitly declare your email here #webmaster's email $debug = $debuggy; #to use this subroutine outside of this program, declare this variable explicity here #1 if you are in debugging mode, 0 otherwise ############################ #for the $error_message, you do need to preceede quotes with slashes (\") $error_message = "

There seems to be a problem with the Photo Gallery program. We regret any convenience this may cause. Please help us, and send us an email. All the relevant error data is already in the email's subject--all you have to do is hit send. Thank you for your support, and we apologize for any inconvenience. "; unless($a){print "Content-type: text/html\n\n"} #if $a == 1, then header outputted, so don't print header again 1; # returns true to calling program unless($debug){print "$error_message"; exit;} #the above prints a more user friendly error message for non-sysadmins (if not in debug mode) print "

You are in debug mode and there seems to be an error. Being the infinitely wonderful perl hacker he is, Michael has included many useful error messages to help you figure out what went wrong. For any more information on a particular error and how to fix it, refer to the GodotWEB Script Archive, where there are help files.\n

Your problem seems to be: $error.

at $time"; exit; }