DIY image gallery in PHP

Whether you want to show off vacation photos, or produce shots for your latest promotional campaign, image galleries make it easy to browse a photo collection. This handy open source tool, written in PHP, makes setting up your own photo gallery a snap.

Whether as part of an intranet, client extranet, integrated into a CMS, or otherwise, image galleries are an increasingly popular way of showing images. And it's not just for the big online photo development types anymore. With open source tools, you can do the same thing for yourself and your clients. One of the most popular tools currently available is Gallery. According to the developers, there are nearly 100,000 current installs of this popular PHP program.

What is Gallery?
Essentially, Gallery is an open source application (licensed under the GNU General Public License) that allows users to create, administer, view, share and manipulate images online through a browser interface. Gallery itself is operating-system independent and will work on any PHP-enabled server. It does not use a database backend, unlike some of the other popular open source gallery scripts such as Coppermine.

The latest version of the Gallery project can be downloaded from It is available as a tarball or a zip file, it doesn’t really matter which you choose so long as the uncompressed files are copied to your active Web directory.

I usually am the type of person that just takes a program and tries to get it running with just intuition and common sense. But in this case, without the benefit of reading the documentation (which I didn’t read the first time through), you will not get a working install. That's because, for whatever reasons, Gallery's developers have not included all the files that you need as part of the archive. It’s a small thing, but you will need to create two of your own blank files for the .htaccess and config.php files and put them into your directory.

The Gallery script is then setup through the browser-based configuration script. The first step supposedly identifies if your system meets the requirements to run the program. You need to have PHP 4.1.x or greater not running in SAFE mode, the mod_rewrite apache module, the correct permissions set, image handling libraries (either NetPBM or ImageMagick) and a few optional libraries to which links for installation are included.

You would think that such a "thorough" system configuration would be sufficient to ensure that you have the right settings for a proper install. Unfortunately, the current version is missing one critical check (that caused my initial install to be non-functional). You need to ensure that the following line is in your php.ini file:

Without that configuration, you can’t upload anything to the Gallery.

The second step of the Gallery Setup offers a long array of advanced configuration features. The dialog box offers a basic description of what the option will do, which seemed to be reasonably accurate. The config options range from directory paths, time limits, session variables and language selection among others. Usually, I don’t pay much attention to language selection, but in Gallery you get the built-in option of allowing users to see the site in the language the browser sends.

Figure A
Basic configuration

Step three allows for color and layout customization of your installed Gallery. Everything is controlled through the script (and the admin interface); there is no modifiable external style sheet to tinker with. This makes it a bit more difficult than normal (when a site-wide style sheet controls everything) to ensure color style consistency between Gallery and the rest of your site.

After all this set-up, you’re ready to jump into the real fun: actually using the program to create your Gallery.

Gallery features
The default Gallery interface is a model of usable simplicity. For my test case I easily set up a Gallery with screenshots from three of my articles. Each Gallery install allows you to manage and create individual ‘Albums’ which through the glory of mod_rewrite get nice clean URLs. So an album's url would look something like this:

Instead of like this:

You can customize the color scheme for each individual album. As well, each individual album also allows for its own set of user permissions for access and modification. Currently Gallery supports jpg, jpeg, gif, png, avi, mpg, mpeg, wmv, mov, and swf as image file formats.

Figure B
Picking an album

Gallery image management features include automatic thumbnail creation, image resizing, rotation, ordering, captioning, and searching. Albums can have read, write, and caption permissions per individual authenticated user for an additional level of privacy.

Figure C
Image management

The Gallery project also includes a subproject called Gallery Remote, which is a desktop application that makes it easier for users to upload their images. If you’re going to have multiple users of a Gallery and some of them prefer a simple Windows type interface, then I highly recommend deploying Gallery Remote as part of the project. Gallery's default browser-based upload works okay, but it doesn’t have the simplicity of a drag-and-drop interface like Gallery Remote.

I originally went out looking for some sort of open source script to deal with a specific and recurring Web development production issue. I was spending an unreasonable amount of time receiving, organizing, and setting up images on preview for clients (and fellow developers). Gallery has made that usually tedious process a breeze. As I’ve grown more comfortable with Gallery usage, I seem to keep finding ways to use it in a production environment. Overall, I’ve found Gallery to be a reliable and stable application that I will continue to use and deploy.

Editor's Picks