Jump to content

Recommended Posts

Hi, i am working on a website and would like to know if there is a gellery on the internet that is free and all that the webmaster has to do is upload pictures into a directory and they are in the gallery. At the minute they are over 20 pics that have thumbnails and popup a bigger version and it takes too long editing the site. Please Advise

 

Link to comment
https://forums.phpfreaks.com/topic/133076-gallery/
Share on other sites

There is the Lazy gallery. http://www.forge22.com/lazy-gallery/preview/ or you can use my customized one which you can throw into your own template.

 

You can see mine @ http://celebdb.outerregion.net or copy from here

 

image_resize.php

<?php
/*=============================================
          Uber-Simple Photo Gallery

            by Sam Perkins-Harbin
               www.forge22.com
          Last Revision: 20 May, 2005
=============================================*/

$image = $_GET['i'];
$max_width = $_GET['w'];
$max_height = $_GET['h'];


$picture_location = $image;
$picture_save = str_replace($image, ".jpg", ".temp");

$im_size = GetImageSize ( $picture_location);
$imageWidth = $im_size[0];
$imageHeight = $im_size[1];


$im2 = ImageCreateFromJPEG($picture_location);



$x_ratio = $max_width / $imageWidth;
$y_ratio = $max_height / $imageHeight;

if ( ($imageWidth <= $max_width) && ($imageHeight <= $max_height) ) {
  $tn_width = $imageWidth;
  $tn_height = $imageWeight;
}
else if (($x_ratio * $imageHeight) < $max_height) {
  $tn_height = ceil($x_ratio * $imageHeight);
  $tn_width = $max_width;
}
else {
  $tn_width = ceil($y_ratio * $imageWidth);
  $tn_height = $max_height;
}



$im = imageCreateTrueColor( $tn_width, $tn_height );

ImageCopyResized ($im,$im2, 0, 0, 0, 0, $tn_width, $tn_height, $imageWidth, $imageHeight);
Header("Content-type: image/jpeg");
Imagejpeg($im,'',100); //to print to screen
Imagejpeg($im,$picture_save,100);
ImageDestroy($im);
ImageDestroy ($im2);



?>

 

gallery.php

<?php
/*=============================================
          Drop-In Photo Gallery

            by Sam Perkins-Harbin
               www.forge22.com
          Last Revision: 26 November, 2005

You may modify this code as you wish, but please
send me any modifications you do, and keep my URL
on the footer!

Rename this file index.php for it to automatically be your gallery,
otherwise name it whatever you want. This file must be used with the 
resize_image.php file to create the thumbnails.

This program uses the image resize script to generate
thumbnails on the fly for a directory. It parses
directory structure, and outputs navigation.
Thumbnails are generated for each image in a directory.
You can specify how many thumbs are displayed per page,
thumbnail size, and if folder navigation should be on.

CSS colors and layout are standard and editable as well.
CSS generates paragraph size based on specified size of
thumbnail. Each paragraph contains the thumbnail, image
dimensions and image filesize.

=============================================*/



$limit = 9;           // number of thumbs to show per page.
$w = 190;              // max width of thumbnails.
$h = 140;              // max height of thumbnails.
$show_folders = 0;     // Set to 1 to show folder list, 0 to turn off
$isize = 1;            // Set to 1 to display image filesize
$idim = 1;             // Set to 1 to display image dimensions

//============================================
// No further options below here.

if($pg = $_GET['pg'])
{
  $thumb = (($pg-1)*$limit);
  $i = $thumb;
}
//if($thumb = $_GET['thumb'])
//  $i = $thumb;
else
  $i = 0;

// get the directory name
$dirlist = dirname($_SERVER['SCRIPT_NAME']);

// split it up
$subdir = explode("/", $dirlist);

// reverse it so directory above images is listed
$subdir = array_reverse($subdir);

// page title name is root dir.
$title = str_replace("_", " ", $subdir['0']);

//$my_uri = "http://" . $_SERVER['HTTP_HOST'] . $HTTP_SERVER_VARS["SCRIPT_NAME"];

if(ereg("\.\.", $_GET['id']))
  header ("Location: ?");


?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<style type="text/css">

h1 {font-size: 16px; margin: 1em; }

#dirnav {height: 16px; position: relative; margin: auto auto 5px auto; clear: both;  border-bottom: 1px solid #aaa; text-align: center; padding: 3px; }
#dirnav ul, #dirnav li {margin: auto; padding: 0; list-style-type: none; }
#dirnav li {float: left; text-align: center;  }
#dirnav a {display: block; padding: 2px 5px 2px 5px; }

#thumbs {width: 100%; margin: 10px; border: 1px solid black; clear: both; text-align: center; }
p.thumb {width: <? echo $w+18; ?>px; height: <? echo $h+32; ?>px; margin: 1em; padding: 3px; float: left; border: 1px solid #000; font-size: 12px; text-align: center; }

#nav {position: relative; margin: auto; clear: both;  border-top: 1px solid #aaa; text-align: center; }
#nav ul, #nav li {margin: auto; padding: 0; list-style-type: none; }
#nav li {float: left; text-align: center;  }
#nav li.current a.page {font-weight: bold; color: #ddd; }
#nav a {}
#nav a.page {display: block; padding: 2px 5px 2px 5px; }
#nav a.prev, #nav a.next , #nav .prev, #nav .next {display: block; width: 65px; padding: 2px 5px 2px 5px; }
#nav a:hover { }

a {color: #999; text-decoration: none; }
a:hover, a:active {color: #d0d0d0; }
a img {border: 1px solid #777; }
a:hover img {border: 1px solid #d0d0d0; }
a.page {color: #999; }

</style>
</head>

<body>

<?

//echo '<h1>Photo Gallery: '.$title.'</h1>';



//-------------------------------- Directory Navigation -----------------------------
function dir_list($dir)
{
  global $title;
  $dlist = array();

  if ($hdir = opendir('./'.$dir))
  {
    while ($obj = readdir($hdir))
      {
        if (((preg_match("/^\./",$obj)==0) && (!eregi('^(.*).[code=php:0]$', $obj))) && is_dir($dir.$obj))
        //if(is_dir($dir.$obj))
          $dlist[] = $obj;
      }
    closedir($hdir);
  }
  else 
    die('Cannot list files for ' . $dir);

  asort($dlist);
  echo "<div id='dirnav'><ul>\n<li>Folders:</li>\n";

  echo "<li> <a href='?'>$title » </a></li>\n";
    $dirtree = explode("/", $_GET['id']); // parse directory tree from passed "d"
  if(!$_GET['id'])
    array_shift($dirtree); // remove redundant "." directory from tree 
    foreach ($dirtree as $dirsub)
    {
    echo "<li> <a href='?d=$dirparent$dirsub'>$dirsub » </a></li>\n";
    $dirparent .= $dirsub.'/';
    }

  foreach ($dlist as $link)
  {
    echo "<li><a href='?d=$dir$link'>[$link]</a></li>\n";
  }
  echo "</ul>\n</div>\n";
}



//-------------------------------------Get image file size ----------------------------------
function getfilesize($size)
{
  $units = array(' B', ' KB', ' MB', ' GB', ' TB');
  for ($i = 0; $size > 1024; $i++) { $size /= 1024; }
  return round($size, 2).$units[$i];
}



//-------------------------------------Set which folder we are viewing----------------



if($_GET['id'])
{
  $d = $_GET['id'].'/';
  $dd = 'id='.$_GET['id'].'&'; // for use in passing to URL strings
  $current_dir .= $d;
}

opendir($current_dir);

if ($show_folders)
  dir_list($current_dir);



//--------------------------------------- Create list of Images ------------------------
$list = array();

if ($dir = opendir('./'.$current_dir))
{
  while ($file = readdir($dir))
  {
      //if((is_file($file)) && ((!eregi('^(.*).[code=php:0]$', $file)) && (!eregi('^(\.htaccess)$', $file))))
      //if((eregi('^(.*).[jpg]$', $file)) && (!eregi('^(.*).[code=php:0]$', $file)))
      //if (eregi('^(([:alnum:])*)\.((j|J)(p|P)(g|G)))$', $file))

    if (eregi('.jpg', $file)) //If file is a JPG
      $list[] = $file;
  }
    closedir($dir);
}

asort($list); // sort alpha
$numtotal = count($list); //total number of thumbs

if ($thumb)
{
  $s = 0;
  while($s < $thumb)
  {
    array_shift($list);
    $s++;
  }
}

$numremain = count($list); // total remaining thumbs



//-------------------------------------- Create Thumbnails and Gallery ------------------
foreach ($list as $pic)
{
   	$fp = $current_dir.$pic;
   	if($i < $thumb+$limit)
   	{
  //echo "<p class='thumb'><tt><a href='$current_dir$pic'><img src='tn/$pic' alt='$pic' /><br />$pic</a> - [".getfilesize(filesize($fp))."]</tt></p>\n";
  $image = $currentdir.$pic;
  $i_size = getfilesize(filesize($fp));
  $i_area = getimagesize($fp);
  $i_width = $i_area[0];
  $i_height = $i_area[1];
  //$i_mtime = date("d F Y ", filemtime($fp));
  $name = str_replace('.jpg', '', $pic);
  echo "<p class='thumb'>
  			<tt>
  				<a href='$current_dir$pic'><img src='image_resize.php?i=$d$pic&w=$w&h=$h' alt='$pic' /><br />
  				$name<br /></a>\n";
    if($idim)
  	echo "			[$i_width x $i_height]";
    if($idim && $isize)
        echo " - ";
    if ($isize)
    	echo "			[$i_size]";
  echo "		<br />
  			</tt>
  		</p>\n";
  $i++;
}
}




//---------------------------------------Page Navigation -----------------------------
$page = 0;
if(!$pg)
  $pg = 1;
echo "<div id='nav'>\n<ul>\n";

if($thumb > 0)
  echo "<li><a class='prev' href='?".$dd."pg=".($pg-1)."'>« Prev $limit</a></li>\n";
else
  echo "<li><div class='prev'>« Prev $limit</div></li>";

while($page*$limit < $numtotal)
{
  $page ++;
  unset($cur);
  if($page == $pg)
  {
    $cur = ' class="current"';
  }
  echo "<li$cur><a class='page' href='?".$dd."pg=$page'>[".($page)."]</a></li>\n";
}

if($numremain > $limit)
  echo "<li><a class='next' href='?".$dd."pg=".($pg+1)."'>Next $limit »</a></li>\n";
else
  echo "<li><div class='next'>Next $limit »</div></li>\n";
echo "</ul></div>Photo Gallery by [<a href='http://www.forge22.com' target='_blank'>Forge22</a>]\n";

?>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/133076-gallery/#findComment-692065
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.