[PHP] thumbnail generator

hi…

alright i wouldn’t bug you guys again for help if i hadn’t reached boiling point.

observe…my attempt at setting up the thumbnail generator :

http://www.band-central.net/photos_chain/index.php

and this is how i want it to look :

http://www.band-central.net/photos_live/chain.php

im pretty sure the problem lies in the thumps.php script but everything i try just isn’t working…i’ve posted the scripts below

thumbs.php :

	<style type="text/css"><!--
		<?php
			include('setup.inc.php');
			echo '.thumb, a { background-color:' . $borderCol . '; }' . "
";
		?>
	--></style>
	<script type="text/javascript">
		function popup(name,width,height) {
			var topPos = (screen.height-height)/2
			var leftPos = (screen.width-width)/2
			var popup = window.open("","Images","width=" + width + ",height=" + height + ",top=" + topPos + ",left=" + leftPos + ",toolbar=0, status=0, menubar=0, resizable=0, scrollbars=no, directories=0, dependent=yes");
			popup.document.open();
			popup.document.write("<html><head><meta http-equiv='imagetoolbar' content='no'><title>Atreyu-Online v.3.0 || Photos</title></head><body bgcolor='<? echo $borderCol; ?>' bottommargin='0' rightmargin='0' leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'><table width='100%' height='100%' border='0' cellspacing='0' cellpadding='0'><tr><td align='center' valign='middle'><a href='javascript:self.close();'><img src='" + name + " 'border='0' alt='Close'></a></td></tr></table></body></html>");
			popup.document.close();
			popup.focus();
		}
		function switchImg() {
			document.images[1].src = document.images[0].src
		}
	</script>
<body BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<?php
//check php version and abort if it is obsolete
	$pv = explode(".", phpversion());
	if(($pv[0] < 5) && ($pv[0] > 3 && $pv[1] < 2) || ($pv[0] <= 3)) die("Your version of PHP (" . phpversion() . ") is obsolete. You need PHP 4.2.0 or above on your server in order to run thumbnailGenerator. Check <a href='http://php.net' target='_blank'>php.net</a> for further information.");
	$selfA = explode('/', $_SERVER["PHP_SELF"]);
	$self = $selfA[sizeOf($selfA)-1];
	$picDir = dir($picFolder);
//READ OUT PIC DIR
	$liste = array();
	while($check = $picDir->read()) if(strpos($check,'.jpg')) $liste[] = $check;
	if($sortBy == "date") {
		$tmp = array();
		foreach($liste as $k => $v) {
			$tmp['file'][$k] = $v;
			$tmp['date'][$k] = filemtime($picFolder . $v);
		}
		($sortByOrder == 'desc') ? array_multisort($tmp['date'], SORT_DESC, $tmp['file'], SORT_DESC) : array_multisort($tmp['date'], SORT_ASC, $tmp['file'], SORT_ASC);
		$liste = $tmp['file'];
	} else ($sortByOrder == 'desc') ? rsort($liste) : sort($liste);
//OUPUT
	$count = 1;
	$output = '';
	//thumbcount
	if($thumbCount == 'on') {
		$deci = array();
		for($i=1; $i<=sizeof($liste); $i++) {
			$deci[$i] = $i;
			while(strlen($deci[$i]) < strlen(sizeof($liste))) $deci[$i] = '0' . $deci[$i];
		}
	}
	if($gallery == 1 && isset($_GET['img'])) { //click through gallery
		$bigPic = $picFolder . $liste[$_GET['img']];
		$imgSize = getImageSize($bigPic);
		$img = (!isset($_GET['img'])) ? 1 : $_GET['img'];
		$next = ($_GET['img'] == (sizeOf($liste)-1)) ? $self : $self . "?img=" . ($_GET['img']+1);
		$output .= '<div style="position:absolute; visibility:hidden;"><img src="' . $bigPic . '" border="0" ' . $imgSize[3] . ' alt="" onLoad="switchImg()"></div>';
		$output .= '<table border="0" cellspacing="0" cellpadding="0"><tr><td align="center" valign="middle" class="thumb"><table border="0" cellspacing="0" cellpadding="' . $borderSize . '"><tr><td class="thumb"><table ' . $imgSize[3] . ' border="0" cellpadding="0" cellspacing="0"><tr><td class="thumb" align="center" valign="middle"><a href="' . $next . '"><img src="loading.gif" border="0" alt=""></a></td></tr></table></td></tr><tr><td align="center" valign="middle" class="thumb">Image ' . ($_GET['img']+1) . ' of ' . sizeOf($liste) . '</td></tr>';
		$output .= '<tr><td align="center" valign="middle" class="thumb">';
		$output .= ($_GET['img'] == 0) ? "" : "<a href='" . $self . "?img=" . ($_GET['img']-1) ."'>Previous Image</a> | ";
		$output .= "<a href='" . $self . "'>Index</a>";
		$output .= ($_GET['img'] == (sizeOf($liste)-1)) ? "" : " | <a href='" . $next . "'>Next Image</a>";
		$output .= '</td></tr></table></td></tr></table>';
	} else { //popup window
		$output .= '<table border="0" cellspacing="0" cellpadding="' . $thumbSpacing . '"><tr>';
		$i = 1;
		foreach($liste as $key => $value) {
			if($thumbCount == 'on') {
				$tC = '<tr><td class="thumb"><table border="0" cellspacing="0" cellpadding="0"><tr><td align="center" valign="middle" class="thumb">' . $deci[$i] . '</td></tr></table></td></tr>';
				$altText = 'Launch' . $deci[$i];
				$i++;
			} else {
				$tC = '';
				$altText = 'Launch';
			}
			$bigPic = $picFolder . $value;
			$imgSize = getImageSize($bigPic);
			$output .= ($gallery == 1) ? '<td><table border="0" cellspacing="0" cellpadding="0"><tr><td align="center" valign="middle" class="thumb"><table border="0" cellspacing="0" cellpadding="' . $borderSize . '"><tr><td class="thumb"><a href="' . $self . '?img=' . $key . '"><img src="generate.php?pic=' . $value . '" border="0" width=' . $thumbWidth . ' height=' . $thumbHeight . ' alt="' . $altText . '"></a></td></tr>' . $tC . '</table></td></tr></table></td>' : '<td><table border="0" cellspacing="0" cellpadding="0"><tr><td align="center" valign="middle" class="thumb"><table border="0" cellspacing="0" cellpadding="' . $borderSize . '"><tr><td class="thumb"><a href="javascript:popup(\'' . $bigPic . '\',' . $imgSize[0] . ',' . $imgSize[1] . ');"><img src="generate.php?pic=' . $value . '" border="0" width=' . $thumbWidth . ' height=' . $thumbHeight . ' alt="' . $altText . '"></a></td></tr>' . $tC . '</table></td></tr></table></td>';
			if ($count == $picsInARow) {
				$output .= '</tr><tr>';
				$count = 1;
			} else $count++;
		}
	}
	echo $output;
?>

generate.php :

<?
	include('setup.inc.php');
	if(extension_loaded("gd")) { //check status of the gd library
		if($randomize == "on") mt_srand((double)microtime()*1000000);
		$sourceImgPath = $picFolder . $_GET['pic'];
		$srcImg = ImageCreateFromjpeg($sourceImgPath);
		$srcImgWidth = imagesx($srcImg);
		$srcImgHeight = imagesy($srcImg);
		($randomize == 'on') ? $srcX = mt_rand(1,($srcImgWidth - $thumbWidth)) : $srcX = ($srcImgWidth - $thumbWidth) / 2;
		($randomize == 'on') ? $srcY = mt_rand(1,($srcImgHeight - $thumbHeight)) : $srcY = ($srcImgHeight - $thumbHeight) / 2;
		if(@imageCreateTrueColor(100,100)) { //check gd library version
			//version >= 2.0
			$desImg = imageCreateTrueColor($thumbWidth,$thumbHeight);
			imageCopyResampled($desImg, $srcImg, 0, 0, $srcX, $srcY, $thumbWidth, $thumbHeight, $thumbWidth, $thumbHeight);
		} else {
			//version < 2.0
			$desImg = imageCreate($thumbWidth,$thumbHeight);
			imageCopyResized($desImg, $srcImg, 0, 0, $srcX, $srcY, $thumbWidth, $thumbHeight, $thumbWidth, $thumbHeight);
		}
		imagejpeg($desImg); //return image
	} else { //return a blank image when gd library is missing
		$desImg = imageCreate($thumbWidth,$thumbHeight);
		imageFill($desImg, 0, 0, imageColorAllocate($desImg, 255, 255, 255));
		imagejpeg($desImg);
	}
?>

setup.inc.php :

<?
	/*************************************
	* thumbnailGenerator v2.23
	* last update: 12|08|2003
	* written by michael kloepzig
	* [email]mischer@save-the-gummybears.org[/email]
	* http://www.save-the-gummybears.org
	*************************************/
	//SETUP
	$picFolder = './';  //PATH TO THE PICS, RELATIVE TO THIS FILE, ENDING WITH /
	$gallery = 0; //0 ... POPUP WINDOW | 1 ... CLICK-THROUGH-GALLERY
	$thumbWidth = 45; //WIDTH OF THE THUMBNAILS
	$thumbHeight = 45; //HEIGHT OF THE THUMBNAILS
	$thumbSpacing = 1; //SPACE BETWEEN THE THUMBNAILS IN PIXEL
	$picsInARow = 9; //NUMBER OF THUMBNAILS IN A ROW
	$randomize = 'on'; //SWITCH RANDOM POSITION OF THE THUMBNAIL CUTOUT IN THE PIC "on" or "off"
	$thumbCount = 'off'; //SWITCH INCREMENT NUMBERS BELOW THUMBNAILS "on" or "off"
	$sortBy = 'name'; //SORT IMAGE FILES BY 'name' OR 'date'
	$sortByOrder = 'asc'; //SORT IMAGE FILES IN ASCENDING ORDER: 'asc' OR IN DESCENDING ORDER: 'desc'
	//LAYOUT
	$bgCol = '#EBEBEB'; //BACKGROUND COLOR OF THE GALLERY
	$borderCol = '#000000'; //COLOR FOR THE BORDERS AROUND THUMBNAILS
	$borderSize = 1; //SIZE OF THE BORDERS AROUND THUMBNAILS IN PIXEL
	$font = 'tahoma'; //FONTS FOR THUMBNAIL COUNT
	$fontSize = '9px'; //FONT SIZE
	$fontCol = '#0000000'; //FONT COLOR
	$fontWeight = 'normal'; //FONT WEIGHT, USUALLY 'bold' OR 'normal'
	$fontStyle = 'normal'; //FONT STYLE, 'normal' OR 'italic'
	$textDeco = 'none'; //TEXT DECORATION, 'none' OR 'underline' OR 'overline' OR 'line-through' OR 'blink'
?>

thats about all…the index.php is just the layout with my site in it…

thanks guys :slight_smile: