/*################################################################################################### ImageGal version 1.0 Author: Lloyd Hannesson (dasme@dasme.org) Date: Oct 31, 2004 Whatsitdo? This script will generate a web gallery from a directory of images Inspired by the AListApart article by Jeremy Keith: http://www.alistapart.com/articles/imagegallery/ For this script to work, a few things must be in place. 1. this file must be named index.php 2. the template file (template.inc.html) must be in the same directory as the index. 3. the css file (style.css) must also exist in the same directory if you are using the default style. 4. an (images) directory must exist with images in it that are 320x240 max. 5. thumbnail images must exist in a (thumb) directory in the images dir. The thumbs must also be named the same as the main image files. The thumbnails can be 50x37 max. 6. If you are using large images make sure to add them to the (large) directory in the images dir. And set the $USE_LARGE_IMAGES to true down below. 7. thats it! 8. if you would like captions. Create a text file in the image dir with the same name as the image, minus the extention. ie. when the script processes image_1.gif it will look for a file named image_1.txt for example: ./index.php ./template.inc.html ./styles.css ./images/image1.gif ./images/image2.gif ./images/thumb/image1.gif ./images/thumb/image2.gif ./images/large/image1.gif ./images/large/image2.gif Would produce a 1 page image gallery containing 2 images. If you do make any improvements to this script, please email me so I can update the master. **** If the above 8 steps aren't followed.. well.. your mileage may vary! :) **** Known problems with this script: This script doesn't allow the user to bookmark a particular page in any way. Seeing as we are using dhtml and js to display all the images, there really is only 1 page to display. //###################################################################################################*/ $MAX_IMAGES = 6; // Set the max number of images per page. $USE_LARGE_IMAGES = false; // will there be a large image popup used? if not, set to false //################################################################################################### // Included here as my webhost doesn't have this function enabled for some reason. // If yours does, this will just be ignored. if (!function_exists('file_get_contents')) { function file_get_contents($filename, $use_include_path = 0) { $data = ''; $file = @fopen($filename, "rb", $use_include_path); if ($file) { while (!feof($file)) $data .= fread($file, 1024); fclose($file); } else { /* There was a problem opening the file. */ return FALSE; } return $data; } } $imgdir = (isset($unix_dir))?$unix_dir:"."; // ability to use a seperate dir for debugging... $dimg = @opendir($imgdir."/images/"); // grab the images directory //Lets build up some arrays of info to better handle all of our data while($imgfile = @readdir($dimg)) { if((substr($imgfile,-3)=="gif") || (substr($imgfile,-3)=="jpg") || (substr($imgfile,-3)=="JPG") || (substr($imgfile,-3)=="GIF")) { $a_img[count($a_img)] = $imgfile; sort($a_img); reset($a_img); // Look for a $img_dir/thumb/* file that matches the filename in the directory listing. // If there is one, set the Key Value pair [IMAGE NAME] => True $filename = "./images/thumb/".$imgfile; if (file_exists($filename)) { $tn_img[$imgfile] = "true"; } // Look for a filename.txt file in the image dir. If it exists load it into an array // with the Key Value pair [IMAGE NAME] => Desc $filename = "./images/".substr($imgfile, 0, -3)."txt"; if (file_exists($filename)) { $desc_img[$imgfile] = str_replace("\"","'",file_get_contents($filename)); } } } // Ok we have everything loaded into our arrays.. Now lets start building the page! $tot_img = count($a_img); $i = 0; $count = 0; $page = 0; while($i < $tot_img) { if($count==0) { // if the count is 0, we have a new page. $page++; $output .= "