image of web host Have you ever wanted an image gallery that allows viewers to download original images without resampling them to a smaller size? Showroom is a file-sharing image gallery that does that, along with displaying images resized dynamically within the browser window.

Showroom uses 4 PHP scripts: One to create the gallery, one to create the thumbnails, one to create medium-sized images, and one to create html files to hold the resized images. A fifth script can upload files, but I find it is easier to just use ftp to upload the scripts and originals and then run them on the server. Here’s how it’s done:

1. The main script reads image names contained in the folder and filters out unwanted files and folders. Filenames are stored in a sorted array.

2. The main script then tests whether folders already exist that contain the thumbs, or the resized images or the html files. If any of those folders don’t exist, the other scripts are called to create them and fill them with content, conveniently named with the same prefix as the original images. Testing for the presence of the folder before calling those scripts reduces unnecessary server computations.

Resized images are scaled based on the aspect ratio of the original. Images that are taller than wide may not fit completely within the browser window, since PHP cannot know the height of a user’s browser. However once the window height is adjusted to fit a taller images, the remaining slides with this aspect ratio will then fit inside the window.

3. Next, the main script loops through the array of image names and creates a thumbnail listing of them, using the thumbnails contained in the thumbs folder for the display. Each loop appends html output to a variable string, which is echoed at the end of the script. Files with a pdf extension are segregated into a special category that uses special thumbnail icons instead of dynamically created thumbnails.

Note: The script that creates the resized images uses the GD library, optimized with the plug-and-play function “fastimagecopyresampled” by Tim Eckel. Imagemagick is another alternative, but Tim’s script is really fast and only a couple dozen lines long.

Contact Twisp WebWorks if you are interested in installing these scripts or in getting the source code
at five-oh-nine 997 6010.
- George