The Kermit Photoalbum Script

Frank da Cruz, Columbia University
fdc@columbia.edu
9 July 2006
Last update: Wed Jul 12 17:39:51 2006

The photoalbum script demonstrates some new features of C-Kermit 8.0.212:

Given a directory containing JPG images, this script creates a website like this one:

http://www.columbia.edu/~fdc/museum

composed of:

The script calls upon the Image Magick component convert, if available, to create the thumbnails. If convert is not available, the index page simply contains text links to each image page. (Click on the links in this paragraph to find Image Magick for Windows or Unix.)

This script requires C-Kermit 8.0.212 Dev.20 or later, which includes the new \fpictureinfo() function. Thus it will not fully work in the current version (2.1.3) of Kermit 95; but it still creates a website of unscaled pictures with all their links functioning.

At the core of the script is the new \fpictureinfo() function:

\fpictureinfo(filename[,array-designator])
The filename must indicate a JPG (.jpg or .jpeg) or GIF (.gif) file. The function examines the file's contents to determine the height and width of the image. If the width is greater than the height, the function returns the digit 1; if the height is greater than the width, the function returns 2. If the dimensions can't be determined for any reason, the function returns 0. If the optional array designator is included, e.g.:

.orientation := \fpictureinfo(foo.jpg,&d)

then the array is created (destroying any previously existing array of the same name) and element 1 is set to the image width (in pixels) and element 2 to the height (in pixels).

Suppose you have some JPG images in a directory on your PC. Make a directory on your web server to hold them, cd to that directory, go back to Kermit on your PC upload them. Then run this script on the web server. Command-line options are as follows. If any option contains spaces, enclose the entire option in doublequotes or curly braces.

Option Description Default
title=text Title for the Web page (enclose in quotes if it contains spaces) Photos
color=name Text color for Web page. Use any color name understood by your browser or "#xxxxxx" notation. Maroon
background=name Background color for Web page. Use any color name understood by your browser or "#xxxxxx" notation. Beige
Language=name English or Spanish English
Height=number Height in pixels for thumbnails 72
Resize[=number] Resize original JPGs to the given number of pixels (default 760), which is applied to the longest dimension of each picture. Don't
Noscale=number 0 = Scale pictures for Web browser; nonzero = don't scale. Scale

The RESIZE option is useful when you have uploaded digital camera images that might be 300K, 1MB, or more each in size, which can be painful to view on the Web over slow connections. In any case, the extra detail is wasted in this case because we tell the Web browser to scale the image to fit anyway. RESIZE replaces each original image with a new one of the given maximum dimension (width or height, depending on the orientation), 760 pixels by default, which is about normal for most Web browsers. In this case, the script has HTML display the images without further scaling (since browser scaling tends produce jaggies and otherwise degrade the image). However, the originals are preserved and linked to from each image page, so you can still see them full size.

Thus for each original image, xxx.jpg, this script can produce:

xxx-t.jpg - The corresponding thumbnail
xxx-r.jpg - The corresponding resized image

The original image is unchanged and keeps its original name.

Limitations:

As written, the photoalbum script operates only on JPG files with extension .jpg. With some fiddling it could be coaxed into working on any mixture of .jpg, .jpeg, and .gif. In Unix, filenames are case sensitive. If you have uploaded your JPGs from Windows to Unix and find that their names are uppercase, you can lowercase them easily with Kermit's new-and-improved RENAME command:

rename /lower *.*

The photoalbum script itself could also be made to accomodate different casings of JPG, JPEG, and GIF, using a pattern like:

*.{[jJ][pP][gG],[jJ][pP][eE][gG],[gG][iI][fF]}
which matches jpg, JPG, Jpg, JpG, jpeg, GIF, Gif, etc etc. This is not a concern in Windows, where filenames are case-insensitive.

Examples:

photoalbum
(no options)   Creates a web site titled Photos using the default color scheme, creating thumbnails 72 pixels high if the Image Magick convert program is available.

photoalbum "title=Our Trip to Iceland"
The same, but the given title is used.

photoalbum "title=Our Trip to Iceland" color=blue background=#4444ff
The same, but with the given title and color scheme.

photoalbum "title=Santo Domingo" color=green background=yellow lang=Spanish
The same, but with a different title and in Spanish.

photoalbum height=100
Creates a web site with all the defaults, except thumbnails will be 100 pixels high instead of 72. If any thumbnails already exist that are not 100 pixels high, they are replaced.

photoalbum height=64 resize
Creates a web site with all the defaults, except original images are resized to 760 and thumbnails will be 64 pixels high.

After you have created your website, you can go back and edit the pages to add explanatory text. But don't do this until you are completely satisfied with the picture selection and color scheme, etc, because every time you run the photoalbum script, it replaces all the HTML pages.

To install the script in Unix...

  1. Install the C-Kermit 8.0.212 Dev.20 or later binary in any directory that's in your PATH. Use "chmod +x" to give it execute permission.
  2. Save the photoalbum script file on disk in any directory that's in your PATH. Use "chmod +x" to give it execute permission.
  3. Change the first line (the "kerbang line") of the photoalbum script file to indicate the full path of the C-Kermit 8.0.212 binary from step 1. CLICK HERE for details.

In Windows...

You should save the script with a ".ksc" filetype. You can run the script from the Kermit 95 prompt with a TAKE command. First CD (in Kermit 95) to the directory containing the JPGs. Then tell K95 to TAKE the script (give the full or relative pathname if it's not in the current directory), with any desired options on the TAKE command line following the script name, e.g.:

K-95> take photoalbum.ksc "title=Antarctica 2006" height=80

(Specify the full path of photoalbum.ksc if necessary.) You'll get lots of error messages about "\fpictureinfo(): no such function" but it will still create a little website with fully functional links. CLICK HERE to see how to run the script "directly" in Windows.


The Kermit Project / Columbia University / kermit@columbia.edu / July 2006