Categories
PHP

Automatic PHP Photo Gallery Script

This php photo gallery script will quickly and easily create a photo gallery from a folder of image files. It will resize (or cropped) thumbnails and cache them for quick access.

Creating image galleries can be time-consuming, and other gallery scripts don’t allow for flexibility or are too bloated for everyday use.  The goal with this script was to create an easy to use script that will allow for me to work with the image, and forget about the code.

This script uses the SimpleImage class to resize images, it has many useful functions that make this image gallery script just work.

PHP Photo Gallery Script Features

  • Resize images automatically using php
  • Resize thumbnails, and crop if needed
  • Cache images for faster access
  • Each load checks if images still exist or have been changed, then resizes only that one image.
  • Customized HTML fragment outputted for each image.
  • Create a custom thumbnail image if needed for any individual image.
  • Ability to handle multiple image galleries within the same page.
  • Set Alt tags for each image, and alt tags can be customized.
  • If sizing images takes too long, the script will auto refresh to complete the resizing of all images
  • Transparent GIF and PNG files keep the transparency when resized.
  • Displays loading graphic while images are being generated; graphic is removed from the page once the image gallery shows.

PHP Usage

<?php
require_once 'gallery.php';

$gallery = new gallery();
$gallery->dir          = 'images/gallery1'; // Relative path to the images folder
$gallery->lg_width     = 1200;
$gallery->lg_height    = 800;
$gallery->sm_width     = 160;
$gallery->sm_height    = 160;
$gallery->crop         = true; // Crop thumbnails; crop=true will make them the exact size, crop=false will resize them no larger than the height and width.
$gallery->html         = '{alt}'; // Custom html fragment
$gallery->alt          = array(
                             'vivid_flowers-wide.jpg' => 'New alt tag text' // specify alt text for any of the images here by using the image file name
                         );
$gallery->alt_default  = 'Gallery'; // default alt tag for the gallery
$gallery->output();
?>

Gallery Script Demo

Crop Demo / With Custom Thumbnail
Gallery Demo / With Custom Thumbnail

Download

Download Automatic PHP Photo Gallery Script