This is a all-in-one-file small and powerful image gallery script with PHP. Just upload your images to directory of script with FTP. It is free for private use. For a demo click on screenshot-image. Features:
- Scann directory and display images in web formats automagically
- Create thumbnail images dynamically on the fly (from all JPEG, GIF, PNG)
- Sort images by name, size or last modified time
- Easily change how many thumbnail-images displayed per page
- Page navigation
- Display image name (trim long filename)
- Display image dimensions: width x height
- Display image filesize in kilobytes
- Display last modified time
- Display number of total images
- Easily change album name, description, width
- Easily change thumbnail width/height
- Automagically select largest dimension to scale thumbnail
- Link to original image file
- Meta title and description
/**
* powered by @cafewebmaster.com
* free for private use
* please donate by paypal or give a backlink
*/$album_name = "Photo Album / Picture Gallery with PHP"; // title (description below)
$album_desc = "This a small -all-in-one-file- but powerful photo gallery script with most needed features like display image filesize, dimensions and sort by name, size, lastmodified time. Create thumbnail images dynamically on the fly, showing pager, total images etc...";$album_width = 600; // width in pixels
$thumb_width = 120; // width of thumbnail images
$thumb_height = 80; // height of thumbnail images$pp = 12; //display how many pictures per page
######################## You dont need to edit below ##########################
$start = $_GET[start] ? $_GET[start] : 0 ;
$sortby = $_COOKIE[sortby] ? $_COOKIE[sortby] : "name" ;
if($_GET[sortby]){
$sortby = $_GET[sortby];
setcookie("sortby", $_GET[sortby], time()+86400 );
header("location: index.php");
}$od = opendir("./");
while($file = readdir($od)){
if( eregi("\.(gif|jpe?g|png)$", $file) ){
$file2 = rawurlencode($file);
$img_arr[$file2] = $file;
$img_arr_filesize[$file2] = filesize($file);
$img_arr_filemtime[$file2] = filemtime($file);list($imagex, $imagey, $type, $attr) = getimagesize($file);
$img_arr_sizexy[$file2] = $imagex."x".$imagey;
}
}asort($img_arr);
asort($img_arr_filesize);
asort($img_arr_filemtime);switch($sortby){
case "time":
$img_arr_final = $img_arr_filemtime;
break;case "size":
$img_arr_final = $img_arr_filesize;
break;case "name":
$img_arr_final = $img_arr;
break;
}$total_images = count($img_arr_final);
foreach($img_arr_final as $k=>$v){
$i++;
if($i < $start+1) continue;
if($i > $start + $pp) break;$img_name = strlen($img_arr[$k]) > 18 ? substr($img_arr[$k],0,16)."..." :$img_arr[$k];
$alt = $img_arr[$k] . " -|- Last modified: " . date("Y-m-d H:i:s", $img_arr_filemtime[$k]) . " ";
$imgl .= "
";
}
for($p=0; $p*$pp < $total_images ; $p++){
$active = ($p*$pp) == $start ? "active" : "" ;
$page_htmo .= "".($p+1)." ";
}$arr_sortby = array("name"=>"Name", "size"=>"Size", "time"=>"Time");
foreach($arr_sortby as $k=>$v){
if($sortby == $k){
$sortby_html[] = "$v";
} else {
$sortby_html[] = "$v";
}}
$sortby_htmo = implode(" | ", $sortby_html);
function make_thumbnail($updir, $img){
global $thumb_width, $thumb_height;$thumbnail_width = $thumb_width ? $thumb_width : 120;
$thumbnail_height = $thumb_height ? $thumb_height : 80;$arr_image_details = GetImageSize("$updir"."$img");
$original_width = $arr_image_details[0];
$original_height = $arr_image_details[1];if( $original_width > $original_height ){
$new_width = $thumbnail_width;
$new_height = intval($original_height*$new_width/$original_width);
} else {
$new_height = $thumbnail_height;
$new_width = intval($original_width*$new_height/$original_height);
}$dest_x = intval(($thumbnail_width - $new_width) / 2);
$dest_y = intval(($thumbnail_height - $new_height) / 2);if($arr_image_details[2]==1) { $imgt = "ImageGIF"; $imgcreatefrom = "ImageCreateFromGIF"; $imgx = "gif"; }
if($arr_image_details[2]==2) { $imgt = "ImageJPEG"; $imgcreatefrom = "ImageCreateFromJPEG"; $imgx = "jpeg"; }
if($arr_image_details[2]==3) { $imgt = "ImagePNG"; $imgcreatefrom = "ImageCreateFromPNG"; $imgx = "png"; }if( $imgt ) {
$old_image = $imgcreatefrom("$updir"."$img");
$new_image = ImageCreateTrueColor($thumbnail_width, $thumbnail_height);
imageCopyResized($new_image,$old_image,$dest_x,
$dest_y,0,0,$new_width,$new_height,$original_width,$original_height);header("Content-Type: image/jpeg"); imagejpeg($new_image, NULL, 80);
}}
if($_GET['thumb']) {
if( in_array($_GET['thumb'], $img_arr) ) make_thumbnail("./", $_GET['thumb']); // against file inclusion
exit();
}$footer = '©';
$css_album_width = $album_width."px";
$css_thumb_width = $thumb_width."px";
$css_thumb_height = $thumb_height."px";echo <<
$album_name
$album_name
$album_desc
Sort by: $sortby_htmo$imgl
cafewebmaster_com;?>
- Log in to post comments