$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"]."

\r\n"; $max = count($images)-1; $end = $start+$maxperpage-1; $counter = 0; while (list($key,$image) = each($images)) { if (($key >= $start) && ($key <= $end)) { $piclink = $PHP_SELF."?cmd=min&pic=".$image; if ($f) {$piclink .= "&f=1"; } $biglink = $PHP_SELF."?cmd=max&start=".$start."&pic=".$image; $table .= ""; $counter++; if (((($counter) % $cols) == 0) && ($key < $end)) { $table .= ""; } } } $table .= "
"; // print the page numbers at the bottom for ($i = 0; $i < sizeof($images)/$maxperpage; $i++) { $page = $i + 1; $nstart = $i * $maxperpage; // if current page, then no need to put if ($nstart == $start) { $table .= "Page $page - "; } else { $table .= "Page $page - "; } } } else { $table = "No files in $dir"; } $line = str_replace("###pictable###",$table,$line); return $line; } // prints the HTML for full size image page with appropriate links function image_print($dir,$pic,$template,$start,$ext) { // find the next and previous images $image_arr = read_data($dir,$ext); $prev = "?cmd=max&start=$start&pic="; $next = "?cmd=max&start=$start&pic="; for ($i = 0; $i < sizeof($image_arr); $i++) { if ($image_arr[$i] == $pic) { if ($i == 0) { $prev = ""; } else { $prev .= $image_arr[$i-1]; } if ($i == (sizeof($image_arr)-1)) { $next = ""; } else { $next .= $image_arr[$i+1]; } break; } } // print out the HTML $lines = file($template); $line = implode("",$lines); $selflink = $GLOBALS["PHP_SELF"]; list(,,,$sizestr) = getimagesize($pic); // patch work to make background gray $piclink = ""; $piclink .= "[ previous | "; $piclink .= "index"; $piclink .= " | next ]

"; $src=$dir.$pic; $piclink .= "

"; $line = str_replace("###pictable###",$piclink,$line); return $line; } // routes commands based on the 'cmd' parameter // min - returns a thumbnail // max - returns the full size image // prints the index otherwise (default) function main($cmd,$dir,$pic,$template,$cols,$save,$mdir,$w,$h,$maxperpage,$start,$ext=".jpg") { switch ($cmd) { case "min" : thumb_print($dir,$pic,$save,$mdir,$w,$h); break; case "max" : echo image_print($dir,$pic,$template,$start,$ext); break; default : echo "Sumit Birla: Photo Album: "; echo $GLOBALS["REQUEST_URI"].""; // you may comment out the includes. this works only for my setup include("../../header.inc"); echo index_print($dir,$ext,$template,$cols,$maxperpage,$start,$w,$h); include("../../footer.inc"); } } main($cmd,$img_dir,$pic,$templatefile,$columns,$save,$thumbs_dir,$thumb_width,$thumb_height,$maxperpage,$start,$ext_pattern); ?>