list-pics.pl, index.cgi - Displays individual pictures in a directory.
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 bring up the image by itself (allowing the browser to resize the image or not).
When invoked from the command line as "./index.cgi -", it updates its database and creates thumbnail images if needed.
To install this program, simply save it as text and copy it to a directory that has GIF, JPG or PNG 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:
From the web, with no arguments:
Lists pictures in a directory, with in-line thumbnails. Like the NCSA/Apache httpd, the file named HEADER.txt (or HEADER.html) is output before the directory listing, and the file name README.txt (or README.html) is output after the directory listing. For each GIF, JPG or PNG file in the directory, this script will look in index.txt for a description of the image.
The images are listed in the same order as in index.txt, with undescribed files being listed last. If the images have thumbnails, they will be shown in-line.
At the top and at the bottom of the list are hyperlinks to the parent directory.
From the web, with the name of an image:
The requested image will be presented in-line on a page that includes hyperlinks to the previous image, the next image, the index, and to the image file by itself. (The latter is for browsers that do not handle <img src> well but do handle <a href>, such as lynx.)
The image's description (as found in index.txt) is displayed above and below the image.
To view the next image in the directory, the user can click on either of the 'next' hyperlinks. This provides a easy way to view all the images in a directory, one after another.
To view the view the 5th image from the end, use "-5" instead of a file name.
From the command line, as "./index.cgi -":
When with an argument of a single hypen, the program updates its database files. The names of images that do not have descriptions are appended to index.txt. That file needs to be manually edited to add one-line descriptions. The image files are analyzed to determine their width and height, and the file .index.txt is rewritten to include this info.
The basic format is 'filename', 'spaces and/or tabs', 'description'. For example:
# Comment: Pet ID tag, DOB, etc
. Pictures of my handsome cat
.. Other pets in our house
- index=Murdock.html dates
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 in the description, such as <a href=""></a> and <b>...</b>.
Comments can be placed in the file by using "# Text".
The description for '.' will appear on each page; it should be a description of the current directory. This is <h1> on the directory page and italics on the individual pictures pages.
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.
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. It has image-type, width, height, filename. Supported image-types are those handled by Image::Size and `ffprobe`.
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/img/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/img/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, while in the directory with image files, use the command "./index.cgi -" to create (or update) the index.txt file (and .index.txt). Be sure to edit index.txt to put images in order and separate groups with a blank line.
Another way to get list-pics.pl 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. You will need to "chmod 755 index.cgi" before or after the transfer.
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 written by Tod Sambar for Win-95).
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 are declared in the index.txt file on the line for '-'.
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 "#dddddd"
background="image" Added to <body> tag
text="white" Added to <body> tag
link="blue" vlink="violet" Added to <body> tag
bgimage="clear" Background for transparent GIFs, "black", "white" or "clear"
thumbwidth=570 Limits total width for in-line thumbnails
index="index.html" Allows alternate index file
namewidth=20 Truncates long file name to 20 characters
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.
SCRIPT_NAME Name of this script (if not 'index.cgi')
QUERY_STRING Name of image to be displayed
REQUEST_URI Name of virtual directory being displayed
USER Signifies command-line mode when set
PATH Used to locate 'djpeg', 'ffprobe' and PBM utilities
index.txt Descriptions of the images
.index.txt Width and height of images and thumbnails
HEADER.txt Plain text to be output before the directory index
HEADER.html HTML text to be output before the directory index
README.txt Plain text to be output after the directory index
README.html HTML text to be output after the directory index
When creating thumbnails, the following programs may be used:
djpeg Creates 1/8th scale thumbnail GIF from a JPG image v6
xvpictoppm|ppmtogif Create thumbnail GIF from an 'xv-3.10' thumbnail
pnmscale|ppmquant Create scaled thumbnail GIF from an image
ffprobe Returns width and height of various movie files
pngtopnm Converts PNG
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.
Does not create thumbnails from first frame of movie files.
Joe Smith - joeinwap,gmail
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