here's the code I use for my gallery, It's simple and easy. No database just upload jpg files to the directory and there you go.
<?php
/*Simple thumbnail gallery by Bret Lanius
Some code from other sources http://Bretlanius.com
*/
function directory($dir,$filters){
$handle=opendir($dir);
$files=array();
if ($filters == "all"){
while(($file = readdir($handle))!==false){$files[] = $file;}}
if ($filters != "all"){
$filters=explode(",",$filters);
while (($file = readdir($handle))!==false) {
for ($f=0;$f<sizeof($filters);$f++):
$system=explode(".",$file);
if ($system[1] == $filters[$f]){$files[] = $file;}
endfor;
}
}
closedir($handle);
return $files;
}
if ($Submit){
$picsize=$select;
}
if (!$picsize){$piczie=40;}
$files=directory(".","jpg,JPG");
foreach ($files as $pic){?>
<A href=# Onclick=imgWindow("<?php echo "showpicture.php?pic=".$pic; ?>",450,400)>
<img src="gd.php?img_name=<?php echo $pic ?>&csize=<?php echo $picsize ?>" border="0" align="top"></a>
<?php
}
?>
The gd.php just resizes pictures and returns a graphic. I forget where this code came from but I use it a bit.
<?
//usage gd.php?img_name=img.jpg&picsize=width
//Default width is 123
/* Informs the browser the data being sent back is a Jpeg Image */
Header ("Content-type: image/jpeg");
/* loads image passed thru script
ie: gd.php?img_name=zoom.jpg */
$src_img = imagecreatefromjpeg($img_name);
/* desired width of the thumbnail */
if (!$picsize)
{$picsize = 123;
}
/* grabs the height and width */
$new_w = imagesx($src_img);
$new_h = imagesy($src_img);
/* calculates aspect ratio */
$aspect_ratio = $new_h / $new_w;
/* sets new size */
$new_w = $picsize;
$new_h = abs($new_w * $aspect_ratio);
/* creates new image of that size */
$dst_img = imagecreate($new_w,$new_h);
/* copies resized portion of original image into new image */
imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
/* return jpeg data back to browser
include a second parameter of a file name if
you just want to save the new file to disk*/
imagejpeg($dst_img);
?>
In the header I have a javascript window opener function of:
function imgWindow(url,w,h)
{
var the_features="width="+ w + " ,height=" +h+ " scrollbars";
the_window=window.open(url,'MAPS',the_features);
var height=window.screen.availHeight;
var width=window.screen.availWidth;
//Calc left
var left_point=parseInt(width/2)-parseInt(w/2);
//Calc top
var top_point=parseInt(height/2)-parseInt(h/2);
the_window.moveTo(left_point, top_point);
//Show me -->
}
</script>
Then in the popup window I have a hybrid PHP/Javascript code
img src="<?php echo $pic;?>" name="theimage" onload="var Iwidth=window.document.theimage.width+40;
var Iheight=window.document.theimage.height+100;
var height=window.screen.availHeight;
var width =window.screen.availWidth;
var left_point=parseInt(width /2) - parseInt(Iwidth/2);
var top_point=parseInt(height/2)-parseInt(Iheight/2);
self.resizeTo(Iwidth,Iheight);
self.resizeTo(Iwidth,Iheight);
self.focus();
self.moveTo(left_point,top_point);"><br>
<script language="JavaScript">window.document.write(window.document.theimage.src);</script>