PHP Thumbnail Image Gallery Script

Description

  • This is an image gallery script that allows you to simply upload new full sized images in FTP and the script will automatically create the thumbnails for those images and add those images to a paged thumbnail gallery suitable for browsing.

Example

Download

Terms of Use

  • Version 1.2.0 and onward is released under GNU General Public License. Basically this means you are free to use the script, modify it, and even redistribute versions of your own under the same license.

What's new

  • 1.2.1 [January 13, 2008] - Code went through another cleanup and comment updates. Goal is to make it so anyone can easily modify it themselves.
  • 1.2.0 [December 26, 2007]
    1. Stripped out broken Imagemagick support.
    2. Cleaned up the code.
    3. Better commented everything.
    4. Redid the gallery layout to use CSS the user can easily change.
    5. Changed the License to GNU General Public License.
  • 1.1.0 [June 2, 2006] - Started cleaning up the code. This version was never publicly released
  • 1.01 [May 11, 2004] - Initial release

Instructions

gallery.php settings

  • Open gallery.php and scroll down to about line 30 and look for $config['size']. Set this to the maximum width or height you want your image thumbnail to be.
  • On the next line in the $config['imagequality'] set this to the JPEG quality you would like your thumbnails to be. I recommend you keep it set to 70
  • $config['rows'] and $config['cols'] are the number of rows and number of columns of thumbnail images you want shown on each page
  • $config['maxShow'] is the number of page numbers to show at one time. for instance if you have 100 pages of images, you can set this to only show the page numbers of the 10 pages close to where you currently are
  • $config['fulls'] is the relative path to the full size images located on your server. Include the trailing slash. example: $config['fulls'] = "photos/";
  • $config['thumbs'] is the relative path to where you want the thumbnail images to be stored. Include the trailing slash.

File Permissions

  • You'll need to change the permission on the directory you set $config['thumbs'] to. CHMOD it to 775 or 777 so PHP and GD2 can automatically write and create your thumbnails in that directory.

Changing the Look

  • The entire gallery table is controlled by the CSS settings you'll find toward the bottom of the gallery.php file. I tried to comment each specific part of the CSS and what it controls so you can easily change the look of the gallery without actually having to actually edit any of the PHP.

Lightbox

Lightbox Support (OPTIONAL)

  • I've had multiple people want to know how to make this gallery work with the Lighbox script or telling me that they modified it (which is great!) themselves. While the above gallery script does not come with Lightbox support, modifing it to work with Lightbox requires very minor changes.
  • In gallery.php edit line 116 to add rel="lightbox" so it becomes echo '<a href="'. $config['fulls'].$imagelist[$i] .'" title="'. $imagelist[$i] .'" rel="lightbox" target="_blank">';
  • Go down to about line 353 and include lightbox.js and its CSS in the page header (it's normal HTML down there).

Comments

Is there a way of simply adding this script to a folder and have it generate the thumbnails for that folder and all subfolders without adding the folder names?
For example, if I have 100 folders with images in, I would have to change the $config['fulls'] to match each folder (directory) name.
I have tried it with $config['/'] or $config['*'] and also leaving it blank $config[''] but none of these work.

There is no easy way in PHP to get the contents of a folder and all sub-folders. The script would need to be modified to get the list of folders in the initial directory then loop through each folder separately and get the contents for each one (doable, but not easily).

the gallery is great but the vertical images get rotated in the thumbnails. Is there a way to prevent this?

I would guess the actual original image is in landscape (horizontal) mode even though it does not show that way to you. So the script isn't actually rotating it, the thumbnail simply shows how the image was actually saved.

Here's why. Modern camera's usually only save images in landscape (horizontal) mode. However, if you have the camera turned when you take the picture, while they still save the picture in landscape mode, they do include an EXIF tag that identifies the orientation of the picture.

Most new software/browsers will read the EXIF tag and display the images as rotated for you (even though the actual image is not saved that way). I'm guessing PHP's GD2 library does not read any of the EXIF tags so you end up with a thumbnail that does not display using the same orientation.

There is likely a way to either (1) read the tag and correctly adjust the thumbnail, or (2) rewrite the necessary tag into the thumbnail using PHP. However, that addition is beyond the amount of time I want to donate into a project I no longer use myself.

I have developed a web site that would benefit from a slideshow of images and I think yours is great and does just what I want.

However, as the code is at present it generates a simple HTML page with with slideshow on it. Is there a way to incorporate the code into my pages?

Down near the bottom of the script there is normal looking HTML that can be customized to use your site template.