Click on any of the pictures to enlarge them to their original size. Photoalbum.cgi page generator script (c) 2004 by David Porter.

Page generator script written in PERL

Photoalbum.cgi is a free script you can use for your picture collections, to easily and quickly create webpage "albums" of jpg (picture) files. The picture albums are created "on the fly" based on whatever jpg files are present in the web server each time the script is accessed.

Contents of ths file: Requirements, Set up, Displaying your album, Setting up Captions, Options, How to obtain the Photoalbum.cgi code

An example of the result is shown here...

If you like this script, to support the author's computer activities and join an optional mailing list for more information, updates, etc. THANKS for your support!
Requirements to use Photoalbum.cgi

Access to a web server or web hosting service. Your photos are accessed via the web, for example

You must be able to move .jpg picture files and the Photoalbum.cgi script file into your web service. Typically this is done using a "file manager" or FTP file-transfer type application. One option for this task (for Windows PCs) is the "FTP Explorer" application which provides a visual user interface for managing web server files, drag/drop, etc.
The server must provide a Perl interpreter accessible to you. Many web services provide a Perl interpreter--you might have to inquire or use the support information to find out its location. Apache web server software which is very common typically provides a Perl interpeter by default.

If you have fulfilled the requirements, now you're ready to prepare the photo album for use...

Set up files in your photo album
Move .jpg picture files into a folder in your web service.
Move the Photoalbum.cgi script into the same folder as your .jpg files. Set its file "permissions" to "755" or "775." This makes the file executable.
Edit the first line of Photoalbum.cgi to reference the location of the Perl intepreter. You may need to ask your web service provider for the correct value. The default in the script is #!/usr/bin/perl.
Optional: in the same folder as the jpg and cgi file, you may create a file called Captions.txt that provides caption labels for each picture, and provides other options for presenting your albums. See below for more information.

We recommend hosting all your picture files in the same directory as Photoalbum.cgi. Should you choose to host picture files in multiple folders, read about the limitations in the documentation on Captions.txt. Also, the *chapter command is a helpful way to support complex, multi-paged album setups.

Now you can view the results...

Displaying a photo album
In web browser software like Netscape or Internet Explorer, enter your web server address, folders, and the script name into the address field. For example, a correctly formed address might look like
When the album displays, you can click on any picture to enlarge it to its original size (the native picture size that is encoded into each .jpg file).
Photoalbum.cgi uses standard "html" protocols, so any web browser software can be used for viewing your albums. The script does not alter ("write" to) any .jpg, script, or text file.
Each picture / caption displayed has a 'bookmark' value you can use to instruct the browser to jump directly to a particular picture. To use, append the bookmark at the end of the address, e.g. scrolls the browser window to display picture #10 directly.


Default script behavior

Photoalbum.cgi tries to open a file named Captions.txt. If found it is opened and interpreted to identify picture files, captions for pictures, and other instructions. Click here for more information about setting up captions and options.

If Captions.txt file is NOT found, Photoalbum.cgi locates all picture (.jpg) files in the folder, these are sorted in numeric / alphabetic order (case insensitive) and displayed.

Defaults for "thumbnail" picture size, page background, headers, fonts, title block, etc. are used to construct and display the album. Many of the defaults and standard behaviors can be adjusted, see information about options below.



You can create a text file to specify pictures to include in the album, supply captions for each picture, and provide other instructions to the Photoalbum.cgi script.

The default filename Captions.txt is accessed by default. File naming and retrieval of caption files is case-insensitive.

To use a filename other than the default Captions.txt, specify it via the browser address line, in the form of a "query string" appended to the web address. For example,
instructs the script to use Album10.txt for retrieving captions and commands.

Create the captions file with a "plain text" editor such as Notepad or tools supplied by your web service. Formatted or "binary" files won't work.
Captions.txt contains multiple lines of text, separated by line delimiter characters (created by pressing Enter). Blank lines are allowed but ignored.
Each text line of Captions.txt specifies either: (a) picture filename and caption text described in this section, or (b) commands to the script (commands are always preceeded by the asterisk * character).
Picture files are usually stored in the same directory as Photoalbum.cgi. However, the script does support subfolder or subdirectory access in a limited way: if the Captions.txt entries show subfolders in the form Folder/File.ext, and if the capitalization used matches the files referenced (capitalization is not adjusted after the fact).
The order in which picture filenames and commands appear is not significant (with one exception, the *chapter command).

Here is an example Captions.txt file, click here to see what the result looks like.
*title An Example photoalbum
*subtitle Presented by David A. Porter
*indent 2
*size 300
*htmlheader Three pictures are presented below:
123.jpg This is the first picture in the series
234 This is the second picture in the series
File name with spaces.jpg This is the <b>third picture</b> in the series.
*htmlfooter Goodbye for now!

Specify the picture filename as the first item in each line, with or without the ".jpg" suffix, followed by a space or "tab" character, followed by caption text of arbitrary length, followed finally by the end-of-line (Enter) character. You can include HTML coding in-line with captions as long as it doesn't interfere with the script-generated HTML.
For file names with spaces, the ".jpg" filename extension is required (see example).
The picture filename may be entered in mixed upper- and lower-case letters. However, Photoalbum.cgi searches for files in case-insensitive mode, and adjusts capitalization to match the files found.
If a picture filename cannot be found, it won't be displayed and no error is generated.
If you supply the same picture filename more than once, only the first file identification is used and subsequent identifications are discarded.
Pictures are displayed in the order given in Captions.txt, unless you use the *sort command.


Commands for options and instructions
The commands documented below can be included in Captions.txt to instruct the script to provide extra functions or adjust the default settings.
Commands are optional--if not used, the default setting is in effect.
Commands are always preceeded by the "asterisk" (*) character, for example *size.

Commands are case-insensitive. They can appear in lower or upper case.

The following commands and usage examples are shown in blue, so you can get an idea of how they would appear in Captions.txt.

*title An Example photoalbum
This is the text contained in the "headline" box at the top of your album page. The default value is "Photoalbum.cgi." You can include any text characters, except it may cause problems if you try to use html tags like <b>.
*subtitle Presented by David A. Porter
The second line of the headline box.
*pagetitle An Example photoalbum by Dave P.
Title for the browser window. If not supplied, this value inherits from the *title setting.
*indent 1
Sets the left margin, in case more or less is needed compared to the default which is an indent of 2. See also the command for *backgroundgif.
*size 300
Sets the width of the "thumbnail" pictures. The default is 250. See also the *random command.
*htmlheader <font face="Verdana" font size="2">
Use this command to include "html" text (plain readable text plus html commands) immediately after the <body> tag in the album. This command can be included multiple times to issue arbitrary amounts of html content. Reference for html syntax and protocol used by Photoalbum.cgi is at
*htmlfooter An Example photoalbum
Like *htmlheader but used for specifying html text to appear immediately before the closing <\body> tag in the album. This is useful for supplying a tag line at the end of the album.

When a Captions.txt file is supplied the default is to show only picture files referenced in it. Including the *scanall command orders the script to also show picture files NOT present in Captions.txt.

*sort or *nosort
Overrides the defaults for sorting or not sorting the picture filenames specified by Captions.txt or in its absence. (See also default script behavior). Sorting is case-insensitive.

*font Verdana, Helvetica, sans-serif
The default font tag for the entire album is "Verdana." The *font command can supply a comma-separated list of font names the browser should search for in order of preference. Font usage renders in different ways in the several types of browser software. Some typical font names are: Verdana, Helvetica, sans-serif, Arial, Courier, Courier New, Georgia, Times New Roman, Geneva.

*fontsize 2
Overrides the default font size for the entire album. The default value is 3.

*backgroundgif mybackgroundfile.gif
This command supplies the bitmap background of your album. The default is the "photoalbum" bitmap provided on this page (click here to see it). Browsers replicate this file to cover the entire page area "behind" your album pictures.
The default size of each "thumbnail" picture is 250 pixels wide, or a non-default value specified by the *size command. The *random command instructs the script to vary the thumbnail width plus or minus 20%, so that the pictures appear in a less regular more invitingly random presentation.
*chapter Chapter heading text
Segments an album into "chapters," and provides a clickable menu of "Chapter heading text" entries to select them. You must provide at least two *chapter commands before the chapter menu will appear (unless you "suppress chapters"--see below). The chapter sequence matches the order in which they appear in the Captions.txt file. Commands appearing before the 2nd *chapter command apply to all subsequent chapters, unless overriden by commands used within a chapter section. When chapter commands are set up, the first chapter is shown by default. However, you can display any chapter by referencing the chapter number in the URL query string, for example, (specifies chapter 2 in the default Captions.txt). Note: to specify both an alternative filename and a chapter specification in the query string, separate them with a comma, e.g. ?Album10.txt,2
This command instructs the script to suppress display of the chapter selection menu, if they would appear otherwise appear. This is helpful to disable the ability to navigate elsewhere in the collection of chapters and simplify the presentation. Without the chapter menu, the user would need to click the "Back" browser command to return to the referring page or otherwise navigate.

Obtaining the Photoalbum.cgi software

Click here to download the software as a file called Photoalbum-cgi.txt. This is necessary because you want to obtain the source text of the script, not order it to be executed. This will move the script code to your workstation, either visible as plain text in your browser or by initiating a download.

Rename Photoalbum-cgi.txt to Photoalbum.cgi.

Move the script to your web service, into one or more of your album folders.

Adjust permissions for each copy of Photoalbum.cgi on your web service. Permissions must be "775" or "755" or allow "execute" capability.