Script generator |
[hide private]
[frames] | no frames]

# Script generator

    Generate HTML image gallery pages.

    Curator is a powerful script that allows one to generate Web page image
    galleries with the intent of displaying photographic images on the Web, or for a
    CD-ROM presentation and archiving. It generates static Web pages only - no
    special configuration or running scripts are required on the server. The script
    supports many file formats, hierarchical directories, thumbnail generation and
    update, per-image description file with any attributes, and 'tracks' of images
    spanning multiple directories. The templates consist of HTML with embedded
    Python. Running this script only requires a recent Python interpreter (version 2
    or more) and the ImageMagick tools.

    All links it generates are relative links, so that the pages can be moved or
    copied to different media. Each image page and directory can be associated any
    set of attributes which become available from the template (this way you can
    implement descriptions, conversion code, camera settings, and more).

    You can find the latest version at http://curator.sourceforge.net

    Input
    ------------------------------

    The image files need to be organized in a directory structure.

    For each image, the following is required:

     - <image>.<ext>: the main image file to be displayed in the html page, where
       <ext> is an image extension (e.g. jpg, gif, etc.)

    The following is optional, and will be used if present:

     - <image>.desc: a per-image description file containing user-provided
       attributes about the photograph.  The format is, e.g.:

              <attribute-name>: <text>
              <text>
              <text>

              <attribute-name>: <text>
              ...

       Each attribute text is ended with a blank line.  You can inclue all the
       attribute fields you want, it is up to the template file to access them or
       not. There are, however, some special predefined attributes:

            - title: A descriptive title for the image (a short one liner).

            - tracks: <trackname1> <trackname2> ...
              specifies the tracks that the image is part of

            - ignore: yes
              specifies that the image should be ignored

     - <image>--<string>.<ext>: alternative representations of the image. Could be
       the original scan plate, or alternative resolutions, or anything else related
       to this image.  The image html page can add links to these alternative
       representations. We assume that we only need to generate an HTML page for the
       main resolution (i.e. smaller resolutions won't have associated web pages)

    To configure the generated HTML files, use --save-templates and modify the code
    that will appear in the output directory.

    The following files can be put in the root:

     - template-image.html: template for image HTML file
     - template-allindex.html: template for global index HTML file
     - template-dirindex.html: template for directory index HTML file
     - template-trackindex.html: template for track index HTML file
     - template-sortindex.html: template for sorted index HTML file

    The template is a normal HTML file, the way you like it, except that it contains
    certain special tags that get evaluated by the script in a special environment
    nwhich contains useful variables and functions.  You can use the following two
    tags:

    <!--tagcode:
    print 'some python code',
    for i in images:
            print 'bla'
    -->

    <!--tag:title-->

    The second tag is implemented as 'print <tag contents>,'. You can put
    definitions, function calls, whatever you like.  Variable bindings and
    definitions will remain between tags.

    The templates are looked up in the following order:
     - user-specified path (-templates option)
     - the root of the hierarchy
     - the dir specified in the env var CURATOR_TEMPLATE

    If not found, simple fallback templates are used. Remember that under unix,
    processing python code with carriage returns will fail the python interpreter
    with a Syntax Error.

    For a complete description of the environment, look at the code.

    Output
    ------------------------------

    Note by default nothing that already exists is overwritten. Use the --no* or
    --force* options to disable or force thumbnails, indexes and image pages.
    Directories which do not contain images (and whose subdirectories do not contain
    images) will be ignored.

    For each image:

     - <image>--thumb.<ext>: associated image thumbnail.

     - <image>.html
       (for each image, an associated web page which features it)

    Thus you will end up with the following files for each image:

     - <image>.<ext>
     - <image>.desc
     - <image>--<string>.<ext>
     - <image>--<string>.<ext>
     - ...
     - <image>--thumb.<ext>
     - <image>.html

    In each subdirectory of the root:

     - dirindex.html: an HTML index of the directory, with thumbnails and
       titles.

    In the root:

     - trackindex-<track>.html: for each track, an HTML index of the track, with
       thumbnails and titles.

     - allindex.cidx: a text index of all the pictures, with image filenames and
       titles, each on a single line.

     - allindex.html: an HTML index of all the pictures, with thumbnails and titles,
       and list of tracks.

     - sortindex.html: an HTML index of all the pictures, with some form of sorting
       This output can be used as a global index for sorting images by
       name/date/whatever.  The images in the author's photo gallery are named
       by date so sorting by name is sorting by date, which the default template
       implements.

    Usage:
    ------------------------------
      curator <options> [<root>]

    If <root> is not specified, we assume cwd is the root.

Version: $Revision: 1.1 $

Author: Martin Blais <blais@furius.ca>

Classes | [hide private]
| Entry
| FCache
| Dir Directory class.
| Image Image specific processing and storage.
| StringStream Simple string stream with a write() method, for replacing stdout when running in script environment.

Functions | [hide private]
urlquote(text) same as urllib.quote but windows compliant |
splitpath(path) Splits a path into a list of components. |
rel(dest, curdir) Returns dest filename relative to curdir. |
splitFn(fn) Returns a tuplet ( dir, base, repn, ext ). |
test_jpeg_exif(h, f) imghdr test for JPEG data in EXIF format |
imgwhat(fn, fast=None) Faster, sloppier, imgwhat, that doesn't require opening the file if we specified that it should be fast. |
getMagickProg(progname) Returns the program name to execute for an ImageMagick command. |
Dir_cmpdates(dir1, dir2) Compare two subdirectories by date. |
checkThumbSize(isz, tsz, desired) Returns true if the sizepair fits the size. |
imageSizeNoCache(filename) Non-caching finding out the size of an image file. |
imageSize(path) Returns the ( width, height ) image size pair. |
generatePage(fn, ttype, envir) Generates an index page, replacing the tags as needed. |
generateSummary(fn, allimages) Generates the text index that could be used by other processing tools. |
readTemplates() Reads the template files. |
readTemplate(tfn) Reads a template file. |
compileCode(pretext, codetext, filename) Compile a chunk of code. |
compileTemplate(ttext, filename) Compiles template text. |
execTemplate(outfile, olist, envir) Executes template text. |
computeTrackmap(imagelist) Computes a map of files in each track. |
clean(allimages, alldirs) Removes the files generated by curator in the current directory and below. |
imageSrc(cd, image, xtra=`'````'`) |
thumbImage(cd, image, xtra=`'````'`) |
scaledImage(cd, image, xtra=`'````'`) |
table(dstdir, images, textfun=None, cols=4) (images: seq of Image, textfun: function, cols: int) |
twoColumns(dstdir, images) |
imagePile(dstdir, images) |
dirnav(cd, dir, rootname=`'``(root)``'`, dirsep=`'``/` `'`) (rootname: string, dirsep: string, dir: Dir, ignoreCurrent: bool) |
next(image, imglist) |
prev(image, imglist) |
cycnext(image, imglist) |
cycprev(image, imglist) |
textnav(dstdir, image, imglist, midtext=`'````'`, middest=None, pcycling=0) (imglist: seq of Image, midtext: string, middest: string, pcycling: bool) |
desc_index(dir) |
sous_titre(i) |
exif(filename) return exif data + title from the photo |
main() |

Variables | [hide private]
| __version_pr__ = ``'``2.0``'``
| installdir = ``'``/usr/lib/python2.5/site-packages/imagizer``'``
| ConfFile = ``[``'``/etc/imagizer.conf``'``,` `'``/home/jerome/.imagizer``'``]``
| config = `Config()`
| fast_imgexts = ``[``'``jpeg``'``,` `'``jpg``'``,` `'``gif``'``,` `'``png``'``,` `'``rgb``'``,` `'``pbm``'``,` `'``pg``...``
| magick_path_cache = ``{``}``
| fcachesizes = `None`
| szre = `re.compile(r'`(`\d`+``)`x`(`\d`+``)`')`
| imageSizeCache = ``{``}``
| dirnavsep = ``'``/` `'``
| html_preamble = ``'``<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 T``...``
| html_postamble = ``'``\n<!--tagcode:\nif \'footer\' in globals():\``...``
| fallbackTemplates = ``{``'``template-allindex``'``:` `'``<!DOCTYPE HTML PUBL``...``

Function Details | [hide private]

### splitpath(path) |
Splits a path into a list of components. This function works around a quirk in string.split().

### splitFn(fn) |
Returns a tuplet ( dir, base, repn, ext ). Repn is '' if not present.

### imageSize(path) |
Returns the ( width, height ) image size pair. Filename must be absolute. This method uses a cache to avoid having to reopen an image file multiple times.

### readTemplate(tfn) |
Reads a template file. This method expects an simple filename.

### execTemplate(outfile, olist, envir) |
Executes template text. Output is written to outfile.

### computeTrackmap(imagelist) |
Computes a map of files in each track. The key is the track name.

### table(dstdir, images, textfun=None, cols=4) |
(images: seq of Image, textfun: function, cols: int) Utility function that generates a table with thumbnails for the given images. Specify textfun a callback if you want to include some text under each image. cols is the number of columns. Of course, you're free to define your own table making function within the template itself if you don't like this one.

### dirnav(cd, dir, rootname=`'``(root)``'`, dirsep=`'``/` `'`) |
(rootname: string, dirsep: string, dir: Dir, ignoreCurrent: bool) Utility that generates an anchored HTML representation for a directory within the image hierarchy. You can click on the directory names.

### textnav(dstdir, image, imglist, midtext=`'````'`, middest=None, pcycling=0) |
(imglist: seq of Image, midtext: string, middest: string, pcycling: bool) Returns an HTML snippet for a text track navigation widget. Set pcycling to 1 if you want it cycling.

Variables Details | [hide private]

  ### fast_imgexts Value:
      ['jpeg',
       'jpg',
       'gif',
       'png',
       'rgb',
       'pbm',
       'pgm',
       'ppm',
      ...

  ### html_preamble Value:
      '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
      <html>
      <head>
         <meta http-equiv="Content-Type" content="text/html; charset=iso-885
      9-1">
         <link rel=stylesheet type="text/css" href="<!--tag:rel(css_fn, cd)-
      ->">
         <title>%s</title>
      ...

  ### html_postamble Value:
      '''
      <!--tagcode:
      if \'footer\' in globals():
          print footer
      -->
      <a name=\'end\'>
      </body>
      </html>
      ...

  ### fallbackTemplates Value:
      {'template-allindex': '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 T
      ransitional//EN">
      <html>
      <head>
         <meta http-equiv="Content-Type" content="text/html; charset=iso-885
      9-1">
         <link rel=stylesheet type="text/css" href="<!--tag:rel(css_fn, cd)-
      ->">
      ...