$max_height) {
$height = $max_height;
}
imagecopyresampled($thumbnail,$img,0,0,0,0,$thumb_width,$thumb_height,$width,$height);
return $thumbnail;
}
// sends the thumbnail back to browser. if the thumbnail does not already exist,
// it is generated. if $save is set to 'true', the image is cached
function thumb_print($dir,$file_thumb,$save,$mdir,$thumb_width,$thumb_height)
{
// if thumbnail does not exist already, create it
if (!(file_exists($mdir.$file_thumb))) {
list($width,$height,$pictype) = getimagesize($dir.$file_thumb);
switch ($pictype) {
case 1 : $img = imagecreatefromgif($dir.$file_thumb); break;
case 2 : $img = imagecreatefromjpeg($dir.$file_thumb); break;
case 3 : $img = imagecreatefrompng($dir.$file_thumb); break;
}
if ($img) {
$thumbnail = thumb_create($img,$width,$height,$thumb_width,$thumb_height);
if ($save) {
switch ($pictype) {
case 1 : imagegif($thumbnail,$mdir.$file_thumb); break;
case 2 : imagejpeg($thumbnail,$mdir.$file_thumb); break;
case 3 : imagepng($thumbnail,$mdir.$file_thumb); break;
}
}
switch ($pictype) {
case 1 : imagegif($thumbnail); break;
case 2 : imagejpeg($thumbnail); break;
case 3 : imagepng($thumbnail); break;
}
}
} else {
// thumbnail file already exists, return it to browser
list(,,$pictype) = getimagesize($mdir.$file_thumb);
switch ($pictype) {
case 1 : $img = imagecreatefromgif($mdir.$file_thumb); break;
case 2 : $img = imagecreatefromjpeg($mdir.$file_thumb); break;
case 3 : $img = imagecreatefrompng($mdir.$file_thumb); break;
}
switch ($pictype) {
case 1 : imagegif($img); break;
case 2 : imagejpeg($img); break;
case 3 : imagepng($img); break;
}
}
}
// read the list of image files in the specified directory
function read_data($data_dir,$ext)
{
$dir_handle = @opendir($data_dir);
if ($dir_handle) {
while ($file = readdir($dir_handle)) {
if (eregi($ext,$file)) {
$files[] = $file;
}
}
closedir($dir_handle);
}
if (gettype($files) == "array") {
sort($files);
} else {
$files = false;
}
return $files;
}
// prints out the HTML for the index page. thumbnail images are calls to self
// with cmd=min
function index_print($dir,$ext,$template,$cols,$maxperpage,$start,$w,$h)
{
$lines = file($template);
$line = implode("",$lines);
$selflink = $GLOBALS["PHP_SELF"];
$images = read_data($dir,$ext);
if ($images) {
$table = $GLOBALS["infocaption"]."