PHP Classes
elePHPant
Icontem

Simple Gallery: Present a picture gallery from image files

Recommend this page to a friend!
  Info   Screenshots Screenshots   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2007-04-11 (9 years ago) RSS 2.0 feedStarStarStarStar 66%Total: 2,957 All time: 1,207 This week: 1,068Up
Version License PHP version Categories
sgallery 1.0GNU General Publi...3.0Graphics, Content management
Description Author

This class can be used to present a picture gallery from images stored as server side files.

It retrieves the list of GIF, JPEG and PNG images files in a given directory and displays thumbnails of the images in a table with links to pages where each image is displayed individually.

The table has a configurable number of columns and rows. When there are more images to display than those that fit in table, navigation links are displayed to browser between multiple gallery pages.

The colors of the page background of different gallery page sections are configurable.

Picture of Mike Rosas
Name: Mike Rosas <contact>
Classes: 2 packages by
Country: Mexico Mexico

Details
   Class written by: Mike Rosas ©2007                                 
   -----------------------------------------------------------------     
   This class can manage a gallery with out using MySQL.               
   It reads the images directly from the directories                     
   All you have to do is to initialize the class and point to         
   the directory containing the images subdirectory and the              
   thumbs subdirectory.                                               
                                                                           
   More info on readme.txt                                            
   -----------------------------------------------------------------     


-------------------------[ R E A D M E ]----------------------------------

1. Introduction
2. Setting it up
3. Functions and parameters
4. Error messages
5. Final notes

-------------------------[ I N T R O D U C T I O N ] ---------------------

This is actually a very simple gallery that does not use mysql, it only requires 
PHP for executing the code.

[*] It includes an index thumb gallery and a image view page. 
[*] It supports multiple paging for the index thumb page and for the image view page.
[*] In the thumb index, you can set the number of images per row and columns.
[*] No previous style is given so your CSS will afect it.
[*] You have a style function to modify some extra stuff.
[*] Error display.
[*] It contains a test function.

Setting it up is really simple, you dont have to modify any actual code, 

-------------------------[ S E T T I N G  I T  U P ] ---------------------

1. Create a directory in your server. (example: gallery01)

2. create two subdirectories in gallery01 (images and thumbs by default)

3. copy your images and thumbs to the right folders 
(images should be already processed)

4. Include require_once("sgallery.class.php"); some where on your PHP document.

5. Initialize a variable with the constructor.

	$gallery = new sGallery();

6. Optinally modify the style with the style function:

	$gallery->style();

7. Where ever you want to print the index gallery or the image page, just call the function:

	$gallery->show();

I recomend you put the code in a table where you can set the width, otherwise it will go 100%

This is pretty much it, but lets review the function to know what are the parameters and
how to use them in the best way.

-------------------------[ F U N C T I N S   A N D ] ---------------------
-------------------------[ P A R A M E T E R S     ] ---------------------

[*] Constructor

$gallery = new sGallery($title, $dir);

The constructor uses two parameters, the first one is the Gallery name and its
displayed in the index page. The second one is the rute to the gallery where ever you have 
your images and thumbs forlder (gallery01 in the setting it up example).

if no values for parameters are indicated, this are the default values:

	$gallery = new sGallery("", ".");

[*] Style

$gallery->style($hcolor, $bcolor, $fcolor, $border, $nav);

The parameter $hcolor sets a color as the background for the TD where the title is displayed
on the index thumb page. The $bcolor is the background color in the TD where the images are 
displayed on the thumb index page. The $fcolor is the background color for the lower TD where
the page anchors are displayed. All collor already includes the # so you dont need to use it
again, just set the number for the RGB. Also the $fcolor is the background color for the 
navigation links on the image view page.

$border is a number representing the px for the border on the thumb index and the image page
view. $nav supports "auto", "up", "down" or "none", it tells where to display the navigational
links on the image view page. Auto displays them in the upper and lower place of the table while
upper only display it in the upper place, same goes for down. its not recomended to use none
becouse no navigational links will apear.

[*] Show

$gallery->show($p, $nc, $nr, $k);

first of all, leave $p and $k just like they are, they are used to build the paging system.
$nc indicates the number of thumbs displayed for all columns, while $nr indicates the number 
of thumbs displayed in all rows, this is handy so that you can display as many images per page
as you want, for example:

	$gallery->show($p, 4, 5, $k);

Displays a gallery showing colums of 4 images and rows of 5 images making a total of 20 images
per page. The default values for $nc and $nr are 5 and 5.

This same function is used to display the image, the $p shows the actual page for the thumb index 
but the $k shows the image to be displayed.

[*] Test Function

If no error ocures in the executing of the constructor, then you can test the script, just run 

$gallery->test();

and some data will be printed:
-> Name: Actual name you have given to the gallery.
-> nimg: Number of Images
-> nthu: Number of Thumbnails
-> dirs: Actual Directory
-> images: List of the images in the images dir
-> thumbs: List of the thumbs in the thumbs dir

-------------------------[ E R R O R   M E S S A G E S ]------------------

When executing the contructor you could recieve some error messages instead of runing succesfully
the class. This are the posible messages and the solution.

[*] ERROR: Can't open image dir
This happends becouse the selected dir does not exist. Maybe you have a typo on the name.

[*] ERROR: No files found in image dir
The dir exists, but there are no images on it.

[*] ERROR: Can't open thumb dir
This happends becouse the selected dir does not exist. Maybe you have a typo on the name.

[*] ERROR: No files found in thumb dir
The dir exists, but there are no images on it.

[*] ERROR: images != thumbs
This is more like a warning, saying that the number of thumbs are not the same as the number of images.

-------------------------[ F I N A L   N O T E S  ]-----------------------

1st. dont be to hard on me, its my first class.
2nd. please give me credit if you ever use this code.
3rd. email me for anything regarding my code mikzael AT hotmail.com
4th. excuse my broken english.
Screenshots  
  • sgallery02.jpg
  • sgallery01.jpg
  Files folder image Files  
File Role Description
Plain text file example1 Example example 1
Plain text file example2 Example example 2
Plain text file example3 Example example3
Plain text file readme.txt Doc. Documentation
Plain text file sgallery.class.php Class class code

 Version Control Unique User Downloads Download Rankings  
 0%
Total:2,957
This week:0
All time:1,207
This week:1,068Up
 User Ratings  
 
 All time
Utility:83%StarStarStarStarStar
Consistency:75%StarStarStarStar
Documentation:91%StarStarStarStarStar
Examples:79%StarStarStarStar
Tests:-
Videos:-
Overall:66%StarStarStarStar
Rank:615