MICA



DESCRIPTION

This CGI program takes a directory of images, creates thumbnails, (if they don't already exist,) displays captions, and provides the user with the option of selecting various sizes of the image to display.

It does so, to a large extent, by looking at the directory structure of the image directory.

The available sizes are controlled by the presence of the directory where the script will store the image (ie., a directory called 1024x768 means the script will provide an option to scale the image to 1024x768)

If you have supplied captions then this script will provide you with a quick word filter.

The script uses imagemagick to do the transformations. This script will prefer to use the pure-perl Image::Magick over imagemagick (through the convert binary)

USAGE

Assume that $IMAGEDIR is /var/www/images if you need a concrete example. This would mean that the URI used to access this directory would be /images.

  1. Copy mica.pl to /usr/lib/cgi-bin, or wherever your cgi-bin lives.

  2. Create a directory that's readable by the web server at $IMAGEDIR . Populate this directory with images.

  3. Create a directory that's writeable by the web server at $IMAGEDIR/thumbnails. MICA won't run unless it finds this thumbnail directory.

  4. (OPTIONAL) Create a directory that's writeable by the web server at $IMAGEDIR/WWWxHHH , where WWWxHHH are your favorite dimensions (i.e. 400x300, 640x480, 800x600, 1024x768)

  5. (OPTIONAL) Create a directory that's readable by the web server at $IMAGEDIR/captions . For each file.jpg in $IMAGEDIR, you can create a caption file file.jpg.txt in $IMAGEDIR/captions.

  6. Load http://server-name/cgi-bin/mica.pl?path=/images/ in your favorite web browser

A NOTE ON CAPTIONS

This script supports captions for the images. The captions are stored in the captions subdirectory, next to the thumbnails directory. Caption files are named as the image file name, but with a txt extension appended to make it easier for the Point-and-Drool types (myself included) to edit them. --(Mike Alborn)

I'd like to point out that this naming convention is almost identical (if not identical) to what feh does for automatic use of caption. Great minds think alike, apparently. ;) --(Mike Carr)

INSTALLATION NOTES

MICA through plain CGI

When running MICA you must always make sure that a path argument is passed to the script. For example, http://server-name/cgi-bin/mica.pl?path=/images/, assuming that your image directory is /images/.

MICA through SSI

When using the script through an SSI, you must make sure that the options passed to the page are forwarded to the script. Mike Alborn uses the following on his website:

    <!--#if expr="$QUERY_STRING" -->
        <!--#include virtual="/cgi-bin/mica.pl?$QUERY_STRING" -->
    <!--#else -->
        <!--#include virtual="/cgi-bin/mica.pl?path=/images/" -->
    <!--#endif -->

This presupposes, of course, that the image directory is /images/

MICA through HTML::Mason

Mike Carr uses the following code on his HTML::Mason site:

    # in /comp/mica
    <%perl>
        my($path) = $ENV{SCRIPT_NAME};
        $path =~ s!/[^/]*$!!;
        $ENV{QUERY_STRING} ||= "path=$path";
        $ENV{DOCUMENT_NAME} ||= 'index.html';
        {
        my(@output) = qx[/usr/lib/cgi-bin/mica.pl];
        shift @output; # Discard "Content-Type: text/html" output
        print join('', @output);
        }
    </%perl>

Then in each image directory I have a index.html that calls &lt;&amp; /comp/mica &amp;&gt;. Basically all the component is doing is artificially adding a path= argument if it doesn't find one already there. Then, it's disregarding the header portion of MICA's output as we're already within a web page.

SAMPLE DIRECTORY LAYOUT

With this layout you would call MICA with argument path=/images, i.e. http://server-name/cgi-bin/mica.pl?path=/images

/var/www/images
Put your images in this directory

/var/www/images/thumbnails
MICA will dump thumbnails into this directory. This directory must exist for the script to run. Explicitly, you must create this directory at present. Ensure that you create it with sufficient permissions to allow the web server process to read/write files into this directory.

If you're in doubt as to what user the web server is running under, you can always make the directory ``sticky'' temporarily and check the ownership of the files as they are created. You can make a directory sticky by running chmod +t directory. You can remove a directory's stickyness by running chmod -t directory.

MICA will automatically overwrite thumbnails if the source file is modified.

/var/www/images/captions
MICA will read captions from this directory if it exists and if appropriately named caption files exist. MICA will automatically create blank template files for you if this directory exists.

A caption file would be named foo.jpeg.txt if the original filename was foo.jpeg

/var/www/images/800x600
If this directory exists (or any directory named WWWxHHH) then MICA will provide a link with a viewing option for these dimensions and will cache files in this directory. Again, MICA will automatically overwrite thumbnails if the source file is modified.
 MICA