It appears you have not yet registered with our community. To register please click here...

Forum Gallery Register FAQ Members List IRC Search Today's Posts Mark Forums Read

Go Back   SMCars - Car Blueprints > Discussion > Offtopic Discussion > Programming

Programming Programming Help Forum.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-06-2007
somebody else somebody else is offline
Cup Holder
 

Join Date: Jan 2007
Posts: 1
A simple but flexible Photo Gallery generator

This is a simple PHP insert that can be placed in any web page (if the server supports PHP.) It looks into a directory for pictures, then makes a thumbnail index with links to full-size pictures. With a simple HTML file and some basic CSS it generates pages like this. If anyone wants I can post a sample web page and CSS to go along with this.

Code:
	<!-- powered by Scott's amazing one-page Gallery_Builder &copy; 2006 -->
	<?php
	echo "\n<!-- begin \"/includes/gallery_builder.php\" -->";
	// The following 5 constant definitions need to be pasted into each gallery page.
	// define ('COLS', 4); // number of columns to display in each row.
	// define ('THUMB', 'thumbnails'); // name of directory where thumbnail images are stored.
	// define ('IMAGE', 'full_size'); // name of directory where full-size images are stored.
	// define ('TN_HEIGHT', 127);
	// define ('TN_WIDTH', 170);
	// $captions = FALSE; // or TRUE, uses image file name.
	// $strip_front = 4; // number of character to strip from front of filename to generate captions.
	// NOTE: thumbnails and full-size images MUST have the EXACT same names.

	if ($dir = @opendir(THUMB)) {
		echo "\n\t<table class=\"proofs\" cellspacing=\"0\">\n";
		$pictures=array();
		readdir($dir); // "./"
		readdir($dir); // "../"
		while (false !== ($imagename =  readdir($dir))) {
			array_push($pictures, "$imagename");
		}
		closedir($dir);
		sort ($pictures);
		$column = 1;	
		echo "\n";
		foreach ($pictures as $image) {
			if ($column == 1) { echo "\t<tr>\n"; }
			$caption = (substr("$image", "$strip_front", -4));
			$caption = (str_replace("_", " ", "$caption"));
			if ($captions) {
				if (!$strip_front) { $strip_front = 4; }
				if (!$caption) {
					echo "\t\t<td><img src=\"" . THUMB . "/$image\" \n\t\t\talt=\"$image\" title=\"$image\" width=\"" . TN_WIDTH . "\" height=\"" . TN_HEIGHT . "\" /><br />$caption</td>\n";
				} else {
					echo "\t\t<td><a href=\"" . IMAGE . "/$image\"><img src=\"" . THUMB . "/$image\" \n\t\t\talt=\"$image\" title=\"$image\" width=\"" . TN_WIDTH . "\" height=\"" . TN_HEIGHT . "\" /></a><br />$caption</td>\n";
				}
			} else {
				if (!$caption) {
					echo "\t\t<td><img src=\"" . THUMB . "/$image\" \n\t\t\talt=\"$image\" title=\"$image\" width=\"" . TN_WIDTH . "\" height=\"" . TN_HEIGHT . "\" /></td>\n";
				} else {
					echo "\t\t<td><a href=\"" . IMAGE . "/$image\"><img src=\"" . THUMB . "/$image\" \n\t\t\talt=\"$image\" title=\"$image\" width=\"" . TN_WIDTH . "\" height=\"" . TN_HEIGHT . "\" /></a></td>\n";
				}
			}
			$column++;
			if ($column > COLS) { $column = 1; echo "\t</tr>\n";
			}
		}
		if ($column != (COLS + 1)) { echo "\t</tr>\n"; }
		echo "\n\t</table>\n";
	} else {
		echo '<h2 style="color: #F00;">We couldn\'t find a folder named "' . THUMB . '"</h2>';
	}
	echo "<!-- end \"/includes/gallery_builder.php\" -->\n";
?>
Feel free to use as you wish.

--scott
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:32 AM.



Design By: Miner Skinz.com
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC6