Fenux.Net - The Life of a Geek
On the subject of Photo Gallery software...
Coding
Posted on 10/16/2004 2:18 pm in Coding
I added the latest version of Gallery to the site. You can see the images I've added here. I discovered Gallery a few weeks ago. A while back, I'd written my own gallery software, but I just didn't have the time to make it more flexible and easier to manage. Gallery has turned out to be far superior than anything I had time to make. I love the Open Source community. You can view my original gallery code by reading on...

This is the code from the gallery.inc file. From here, it's just a matter of make a new instance of the class and telling it to display. There's also a nice little perl script for generating the thumbnails and resizing the images.

showgallery = 1;
			$this->parseform();
			
			// Change these to change the gallery
			$this->basedir = "/usr/local/www/okcbynight.com";
			$this->thumbdir = "/images/gallery/thumbs/";
			$this->imagedir = "/images/gallery/";
			$this->columns = 3; // Number of columns to use.
			$this->maxrows = 5; // Rows per page
						
			$this->imagecount = 0;
			$this->rowcount = -1;
			$this->column = $this->columns;

			if ($this->showgallery)
			{
				$this->LoadImages();
				$this->startrow = ($this->pg - 1) * ($this->maxrows);
				$this->endrow = $this->startrow + $this->maxrows - 1;
				if ($this->endrow > $this->rowcount)
					$this->endrow = $this->rowcount + 1;
			}
		}
		
		function LoadImages()
		{
			$directory = opendir($this->basedir . $this->thumbdir);
			while ($newfile = readdir($directory))
			{
				if ($newfile != '.' && $newfile != '..')
				{
					if (preg_match("/[.jpg|.gif|.png|.bmp]$/i", $newfile) > 0)
					{
						if (file_exists($this->basedir . $this->imagedir . $newfile))
						{
							$this->imagecount++;
							$this->column++;

							if ($this->column >= $this->columns)
							{
								$this->column = 0;
								$this->rowcount++;
							}
							
							$this->images[$this->rowcount][$this->column] = $newfile;
						}
					}
				}
			}
			
		}
		
		function ShowIndex()
		{
?>				
ShowPages();
			for ($i = $this->startrow; $i endrow; $i++)
			{
?>					
columns; $j++)
				{
					$rowarray = $this->images[$i];
					if (array_key_exists($j, $rowarray))
					{
						$this->ShowImage($this->images[$i][$j]);
					}
				}
?>					
ShowPages();
?>				
">thumbdir . $image; ?>" border="0"> columns; ?>" align="center" valign="top">

Go to Page: pg > 1) print "pg - 1) . "'>"; $endpg = ceil($this->imagecount / ($this->maxrows * $this->columns)); for ($i = 1; $i pg == $i) print " " . $i; else print " " . $i . ""; } if ($this->pg pg + 1) . "'>Next->"; ?>

showimage = $_REQUEST["img"]; $this->showgallery = 0; } if (array_key_exists("pg", $_REQUEST)) { $this->pg = sprintf("%d", $_REQUEST["pg"]); } else $this->pg = 1; } function ShowGallery() { if ($this->showgallery) { $this->ShowIndex(); } else { ?>

imagedir . $this->showimage; ?>" border=0>

showimage; ?>

Click Here to Go Back


©2009, Jason Burgess
All Rights Reserved