NAME

list-pics.pl, index.cgi - Displays individual pictures in a directory.


SYNOPSIS

When accessed by a web server with no arguments, this program displays a list of images in the current directory with one-line descriptions. Any thumbnail images in the directory will be displayed in-line.

When a single image is selected, it is displayed along with its one-line description. Included on the page are hyperlinks to the previous image, the next image, and the index. Clicking on the image will advance to the next image in the directory.

When invoked from the command line, it updates its database and creates thumbnail images if needed.


DESCRIPTION

To install this program, simply save it as text and copy it to a directory that has GIF and JPG images. Rename the file to be index.cgi. On Unix systems, mark the file as being executable by using the command ``chmod +x index.cgi''. (This program also works on Win-95/98/NT web servers that recognize ``index.cgi'' as a default document.)

There are three modes of operation:

Format of index.txt

The basic format is 'filename', 'spaces and/or tabs', 'description'. For example:

  .             Pictures of my handsome cat
  ..            Other pets in our house
  -             index=Murdock.html
  Murdock1.jpg  Sleeping
  Murdock2.jpg  Eating

The one-line descriptions can actually be more than one line long. Any line that starts with leading blanks or tabs is a continuation of the previous line. Simple HTML can be used, such as <A></A> and <B></B>.

The description for '.' will appear on each page; it should be a description of the current directory. The header tags <H1></H1> may be used here.

The description for '..' will be used on the index page where it links to the parent directory.

Options for the program are set via index.txt using the description for '-'. These are described under OPTIONS.

Images can be grouped together by using blank lines as separators.

Format of .index.txt

The file .index.txt is recreated whenever there is a newer file in the directory when invoked as ``./index.cgi -''. There is no need to manually edit this file.

Installation hints

Save a copy of this file as 'index.cgi' in a directory full of images. For UNIX users, the easiest way is to go to the shell and use:

   lynx -source 'http://www.inwap.com/mybin/index.cgi?list-pics.pl' >temp
or
   wget -O temp 'http://www.inwap.com/mybin/index.cgi?list-pics.pl'
   chmod 755 temp
   cp temp public_html/images/index.cgi; rm temp

If you have more than one directory full of images, 'cd' into each one and then use

   ln $HOME/public_html/images/index.cgi .

to make a hard link to the script. Using 'ln' instead of 'cp' makes it possible to update all the copies at once when a newer version becomes available. (The instructions above use 'temp' so that will work right.)

Then 'cd' to the directory with GIF and JPG files and use the command ``./index.cgi -'' to create (or update) the index.txt file.

Another way is to go to http://www.inwap.com/mybin/ and view list-pics.pl. Use the browser's menu, ``File | Save As | Source'', and save using the name index.cgi. Then use the ftp program to upload the file to the web server. Be sure to use ASCII mode.

This program can also be used on Windows-95/98/NT by any web server that can handle CGI programs written in perl (such as the one at http://www.sambar.com/ written by Tod Sambar).

Installation hints for Windows-95/98/NT

The Sambar web server (http://www.sambar.com) pays attention to the first line of the perl script if it starts with ``#!''. There are ways of telling the Sambar server how to find the perl executable. [These hints were accurate as if February 2001; things have changed.]

  Option 1:
    MKDIR D:\usr
    MKDIR D:\usr\local
    MKDIR D:\usr\local\bin
    COPY "D:\Program Files\sambar42\perl\perl.exe" D:\usr\local\bin\perl5.exe
  Option 2:
    Change the first line of the file to point to the perl executable.
    Be sure to use the ~ form and forward slashes;  if Sambar is installed
    in "D:\Program Files\sambar42\", use this:
        #! D:/PROGRA~1/sambar42/perl/perl.exe
  Option 3:
    Delete the "#! /usr/local/bin/perl5" line so that the file starts
    with a poundsign and space instead of poundsign and exclamation point.
    You may have to associate ".CGI" with the perl executable.
    Windows Explorer -> View -> Options -> File Types.
    "CGI" open with "D:\Program Files\sambar\perl\perl.exe".
  Option 4:
    Use the cygwin tools (www.cygwin.com).

The advantage of Option 1 is that it allows this CGI script to run unmodified on Unix and Win32. That comes in handy if you ever download an updated version of this script from the inwap.com web site.

/cgi-bin/list-pics.pl

It is possible to use this program on a web server that only allows CGI scripts to be executed out of the /cgi-bin/ directory. Such usage is deprecated, and not documented here.

Preparing the images

Many digital cameras create JPG images with unreasonably high 'Q' values. The size of the file can be reduced to 1/3rd or 1/4th of its original size by simply resaving the file with a 'Q' value of 75. Thumbs Plus from http://www.cerious.com/ has a batch-conversion mode that can do this.

When tranferring images from the Olympus digital camera, there are two annoyances: The file names are PIC00001.JPG through PIC00120.JPG, and the date on the file is when it was downloaded, not when the picture was taken. The program 'rename-oly' in http://www.inwap.com/mybin/ fixes both problems.


OPTIONS

Options are declared in the index.txt file on the line for '-'.

  bydesc byname bysize bydate   Ignored (compatibility with list-files.pl)
  table notable                 Ignored (compatibility with list-files.pl)
  dates nodates                 Shows or suppresses (default) listing file's date
  thumbnails nothumbnails       Shows (default) or suppresses in-line thumbnails
  bgcolor="black"               Added to <BODY> tag, default is "#cccccc"
  background="image"            Added to <BODY> tag
  text="white"                  Added to <BODY> tag
  link="blue" vlink="violet"    Added to <BODY> tag
  bgtable="clear"               Background for transparent GIFs, "black", "white" or "clear"
  thumbwidth=570                Limits total width for in-line thumbnails
  imgsrc="../img/"              Allows images to be redirected elsewhere
  index="index.html"            Allows alternate index file
  namewidth=20                  Truncates long file name to 20 characters


NOTES

Avoid using file names with embedded spaces or '#' characters. (Those two special characters in URLs confuse many browsers.) File names with embedded blanks can be listed in index.txt by using a tab after the file name.


ENVIRONMENT

When run by the web server, these are part of the CGI protocol.

  SCRIPT_NAME           Name of this script (if not 'index.cgi')
  QUERY_STRING          Name of image to be displayed
  PATH_INFO             Image location when run from /cgi-bin/
  PATH_TRANSLATED       Image location when run from /cgi-bin/

When run from the command line

  USER                  Signifies command-line mode when set
  PATH                  Used to locate 'djpeg' and PBM utilities


FILES

  index.txt             Descriptions of the images
  .index.txt            Width and height of images and thumbnails
  HEADER.txt            Text to be output before the directory index
  HEADER.html           HTML text to be output before the directory index
  README.txt            Text to be output after the directory index
  README.html           HTML text to be output after the directory index


EXTERNAL PROGRAMS

When creating thumbnails, the following programs may be used:

  djpeg                 Creates 1/8th scale thumbnail GIF from a JPG image
  xvpictoppm|ppmtogif   Create thumbnail GIF from an 'xv-3.10' thumbnail
  pnmscale|ppmquant     Create scaled thumbnail GIF from an image

On Windows-95/98/NT, only DJPEG.EXE is used. A copy of that program can be found on the http://www.inwap.com/mybin/ web site.


DIAGNOSTICS

Error messages are displayed as HTML to the user. Only one is expected to occur; ``Unable to read directory'' happens when the directory is accidentally protected against reading.


BUGS

Does not handle PNG (or any other image format other than GIF or JPG) gracefully. Needs to be rewritten to use just the file name (without the .GIF or .JPG extension) as the keyword in index.txt.


AUTHOR

Joe Smith - js-cgi@inwap.com - http://www.inwap.com/u/joe/


SEE ALSO

Other programs that can be found at http://www.inwap.com/mybin/

  list-files.pl         Lists files in a directory in alphabetical order
  list-imgs             Recursively updates .index.txt for new images
  djpeg.exe             'djpeg' compiled for Windows-95/98/NT