Name

gallery2.py — creates gallery of pictures in a directory, includes a simple GUI

Synopsis

gallery2.py -d galleryDirectory [ cfFghprstuvwx ] [...]

Description

Gallery2.py creates static pictures galleries, one for each directory it is processing.

This functionality means that it is easy to create a large hierarchy of galleries. The hierarchy will have the same structure as the hierarchy gallery2.py recursed through. Navagation links to parent directory and all sub directories are included in the galleries.

If the pictures contain EXIF data, for example a timestamp, this information is automatically extracted and displayed at the picture page. As gallery2.py now uses the Python Imaging Library to extract the EXIF data, a PIL version 1.1.4 or greater is necessary for EXIF extraction. If an ealier version of PIL is used EXIF data is not extracted.

Gallery2.py has many options, but runs fine with just a single option given. The destination must be given. The simplest command is gallery2.py -d gallery

Gallery2.py makes a fine cron job, automatically skipping directories where no change has taken place. To determine if a gallery needs updating, gallery2.py looks at the unix timestamps of all pictures is the source directory and compares the largest to the unix timestamp of the index.html in the destination directory. If the picture timestamp is larger, the gallery is generated.

The title of a gallery can be given on the commandline or stored in the source directory in the file called title.txt

Examples

  1. gallery2.py -d gallery creates a gallery, using defaults, of pictures in the current directory and stores it in ./gallery/

  2. gallery2.py -s /home/pj/billeder -d /tmp/new_pictures creates a gallery of pictures in /home/pj/billeder/ and stores it in /tmp/new_pictures/

  3. gallery2.py -s /home/pj/all_pictures -d /home/pj/public_html/all_pictures -r creates a hierarchy of directories containing galleries. The new hierarchy is created in /home/pj/public_html/all_pictures/. The galleries contain navigation links to parent directory and all sub dirrectories.

  4. gallery2.py -g fires up a simple GUI

  5. gallery2.py -F "Python is fun to program in<http://www.net-es.dk/~pj/python/>" creates a link in the footer

  6. gallery2.py -x -s /tmp/new_pictures updates all picture pages with data from the xml file in each /tmp/new_pictures

  7. gallery2.py -x -r -s /tmp/new_pictures recursively updates all picture pages with data from the xml files in each directory starting with /tmp/new_pictures.

  8. gallery2.py -r -s pics/ -d kurt --faster --hoverColor red --bgColor yellow --fgColor green --lnColor lightblue --lnVisitColor purple creates an ugly looking gallery.

Overview of options

Gallery2.py has accumulated a fair amount of options, some of which are available through the GUI. Some have a long format (--destinationdir), some don't. The most often used have both a short form (-w) and a long form (--width).

For a quick overview simply type gallery2.py -h for a list of options including a brief description.

Defaults

These defaults are set in gallery2.py. It is a simple matter of changing the values, if the supplied ones don't suit you.

Option defaults

--bgColor

"#34577A"

-C, --columns,

4

-f, --fullsize,

No

--faster

No

--fgColor

"#EAEAEA"

--force

No

--lnColor

"#C0C0C0"

--lnVisitColor

"#C0C0C0"

--hoverColor

"#D0D0D0"

-p, --padding,

5 pixels

-s, --sourcedir,

Current directory

-t, --title,

If title is given on command line use that, else look for title.txt and use the content. If title.txt is not found use source dir name.

-u, --thumbwidth,

160 pixels

-w, --width,

640 pixels

Options

Command line options

--bgColor

Set background color.

-C, --columns,

Sets number of columns in gallery

-d, --destdir,

Destination directory. This is where gallery2.py creates the gallery. It is not necessary that the path to the destination directory is present. gallery2.py creates directories in given path automatically. The destination directory muse not be below the source directory.

-f, --fullsize,

Fullsize pictures are included in gallery if this option is given

-F 'name <URL>, --From 'name <URL>,

Add a text which is a link in the footer. Usage like this:

  1. gallery2.py -F "Per Jensen <mailto:per@net-es.dk>"

  2. gallery2.py -F "Nice ødegård in Sweden <http://www.net-es.dk/~pj/billeder/ryssberget/overtagelse/gallery/index.html>"

--faster

Use a faster resizing algorithm at the expense of quality.

--fgColor

Set foreground color.

--force

Regenerates gallery even though the pictures are younger than the index.html file. This option is always on when gallery2.py is driven through the GUI

-g, --gui,

Fire up the GUI. Other options given on the commandline will be reflected in the GUI.

It is allowed to create many jobs in the gui while galleries are being processed. Every time the "Create gallery" button is pressed, a job request is posted to an internal queue. The user is free to make any number of job requests. Gallery2.py keeps processing until the job queue is empty.

The "Messages" button opens a window where most messages from gallery2.py are shown. Alle lines are prefixed with a job number.

-h, --help,

Get a brief description og available options

--lnColor

Set the link color

--lnVisitColor

Set the color of visited links

--hoverColor

Set the color of hovered links, both visited and non visited ones.

-p, --padding,

Number of pixels used as padding in the HTML table constructed

-r, --recurse,

Recurse through a directory structure and construct a gallery directory in each directory which contains pictures. As a single title cannot be used when recursing, the title used, is either the name of the directory being sprocessed or the contents of the title.txt file in the directory being processed.

If a destination directory has been specified, the above mentioned gallery subdirectories are not created. The directory itselv will be the gallery directory.

-s, --sourcedir,

Path of directory which will be processed. The gallery is placed in the specified destination directory.

-t, --title,

The title set as the HTML document's title and the 'headline' above the table of pictures. This option has no effect when --recursion is used. If title.txt is found in sourcedir, use contents as title. This is always true in recursion mode, and true if no title is given on command line when not recursing

-u, --thumbwidth,

Set the width of thumbnail pictures in landscape mode. This setting is used as height for pictures in portrait mode

-v, --version,

Print the version number of gallery2.py

-w, --width,

Set the width of resized pictures in landscape mode. This setting is used as height for pictures in portrait mode

-x, --updateFromXML,

Updates a gallery from xml file. This means that you can edit the xml file, perhaps through a web interface and the descriptions and other properties will be set in the gallery.

Installation on a *nix system

Gallery2.py is installed using the Python distutil module.

  1. Requirements

    1. Python 2.1 or better must be installed, download from python.org

    2. Python Imaging Library (PIL) must be installed, download from Pythonware

    3. PyXML must be installed if updating from xml file is needed, download from sourceforge

  2. Installation

    1. Download the Gallery tar archive and unpack it somewhere suitable, for instance /tmp

    2. Change directory to the /tmp/gallery2.py-2.0

    3. Execute the setup script: python setup.py install

      If this is done as a nonroot user, the package is installed in ~/lib/python-version/site-packages/gallery2 and the doc files in ~/share/gallery2. The main script is installed in ~/bin

    4. Set your PYTONPATH to include the gallery2 package. If your username is 'pj' set PYTHONPATH=/home/pj/lib/python-version/site-packages in your environment

Installation on a Windows system

Gallery2.py can be installed on Windows using the usual procedure of downloading and executing a few automatic installers.

This procedure is known to work on Windows XP Pro (user=administrator)

  • Installation

    1. Get Python this URL: Python for Windows

    2. Download the Python Imaging Library (PIL)

    3. Download the Gallery2.py

    4. Install Python by executing the downloaded installer.

    5. Install PIL by executing the downloaded installer.

    6. Install Ballery2.py by executing the downloaded installer.

In the Explorer doubleclick C:\python22\lib\site-packages\gallery\gallery2-win.py

Environment

Files

History

Contact information

The author is Per Jensen with help from several people, who have contributed ideas and bugfixes. Gallery.py has a homepage at this URL http://www.net-es.dk/~pj/python/

My email address is

Credits

I have received help from the following people. The list belov is in no particular order. All fixes and comments have been most welcomed. Thanks.

  1. John Redmond reported broken status message regarding title

  2. Kam-Yung provided a bugfix for retrieving EXIF data from the pictures.

  3. Roger Ferguson reported success on an iMac.

  4. Vineet Jain for e bugfix and request for index.html in toplevel directory of hierarchy, even if no pictures are present.

  5. Nicolas for showing me how to make a simpler Windows install procedure

  6. Francisco Borges found an error when recursing and using the -destination option.

  7. Thomas Rijniers for many changes, notably use of PIL's EXIF extraction features

  8. Robert F. Tobler for letting me include his fine 'exif' module.

  9. Hans-Peter Jansen contributed '--from' option and tidied up the sourcecode

  10. James contributed the very nice color scheme

  11. Peter Dyson and Rick Robino pointed out spelling errors

  12. Kees Serier fixed file globbing on Windows platforms

  13. Fredrik Lundh helped out solving a unicode related bug

Bugs

Doc version

$Revision: 1.30 $, $Date: 2004/04/23 20:49:29 $