Defcon:Blog Keklkakl blog blag

plsgen – Perl Simple Gallery Generator

plsgen, short for Perl Simple Gallery Generator, is a naive approach to image gallery creation for web. Greatly simplified, plsgen is a perl-script that iterates over image files in the working directory where it is executed, creates rescaled images suitable for thumbnails and web display, and creates fairly simple HTML pages based on user created template files. All content created by plsgen is static, so album generation can be done off-line before upload.

Latest version:

Development version, in git:

Demos, see it in action:

Requirements

Perl modules

Programs

  • convert from ImageMagick

http://www.imagemagick.org/

  • jhead

http://www.sentex.net/~mwandel/jhead/

And, of course you probably want to publish whis on a Web server. The generated result is static HTML, so no requirements at all exist in regard to type and functionality of HTTP daemon.

Debian users should be able to pull inn the requirements using

apt-get install libappconfig-perl libimage-exiftool-perl imagemagick jhead

Ubuntu users, add 'sudo' to the front of that 😛

Installation

Place the navigation JavaScript and the CSS file somewhere convenient on your Web server.

Place the template files (index.tpl, full.tpl) where You want, I prefer having them located in /usr/local/share/plsgen

Place the executable script so that execution is practical. I place it as /usr/local/bin/plsgen so that I have it in my search path.

Take a look at the shipped configuration file. plsgen looks for a config file as /etc/plsgen.cfg, as ./plsgen.cfg or ../plgen.cfg relative to where it is executed. Alternatively, the –config option allows you to override the default locations. The shipped config lists all configuration options, along with their default values (used if no config present).

Execution / Use

plsgen is written to be ececuted in a directory filled with image files, and will create all its data in this directory. The resulting album will list all present image files of types JPG, PNG and GIF. A display-size and thumbnail image will be created for each image, and will be stored in the sub-directories view and thumbs (respectively).

Recognized commandline options are:

    --title='Your album title'
        Sets the album title. Title will be stored in .title
        If no title is given, it will be read from .title, if present
    --htmlonly
        Add this option to only generate HTML files
        No image operations will be performed with this option
    --noexif
        Forces EXIF data block not to be written to HTML output
    --config=/path/to/config
        Overrides default config file location.
        Default is to look for ./plsgen.cfg, then ../plsgen.cfg
        and finally /etc/plsgen.cfg.
     --help
        Displays a list of available commandline options

File overrides: comments, title, index image.

plsgen supports static gallery- and image comments. To get descriptive text or author comments on a gallery, add a file with the name 'comment.txt' to the directory before generating the album. The file is read, and injected verbatim, into all index* files generated, pre- and post-padded with the content of the comment-{pre,post} configuration variables.

To add an image comment, create a text file named identically to the image filename, plus the suffix .txt. So, if an image is named 'AnImage.JPG', the corresponding comment file should be named 'AnImage.JPG.txt'

If you wish to pre-seed the gallery title, you may do so by putting the gallery title on a single line in a file named '.title'. The title is read from this file if no title is given on the command line, and it is present. Note that if a title is given on the command line, that title will be used, and also will overwrite any content in the .title file.

A reference to an “index image”, simply the first image in the set, is saved in the file '.indeximage', if this file does not previously exist. To override the chosen index image, simply put the filename you would rather have used in this file. The index image is used bu the included example index.php and rss.php

Index front-end and RSS support

Included is a sample front-end index, and an accompanying RSS generator written using PHP. To use these, take a look at the PHP source, make personal adaptation (at least change references to my site to your own), and place both php files, plus indexstyle.css in a directory where you keep your albums as sub-directories.

E.g.:
  Web Root
  |-- galleryset1
  |   |-- image1.jpg
  |   |-- image1.jpg.txt
  |   |-- image2.jpg
  |   |-- comment.txt
  |    `- .title
  |-- galleryset2
  .     ...
  |-- nav.js
  |-- style.css
  |-- index.php
  |-- indexstyle.css
   `- rss.php

Changelog

0.3 -> 0.4

# DONE: Removed some default values in config, allowing empty options
# DONE: Added latest.php, a hybrid between index.php and rss.php ..
# DONE: Gathered all user-related data in php-files as variables on top.
# BUGFIX: Added missing alt-tags to img-tags generated
# BUGFIX: Shipped templates and config now give validating HTML
# BUGFIX: Prepped up index.php to validate aswell
# REMOVED: Will not use perlmagick et. al, removed TODO.

0.2 -> 0.3

# DONE: Config option for size of view/thumbnail
# DONE: Config option to disable arrow-up navigation
# DONE: Config option to disable image rescaling ?
# DONE: Multithreaded resizing, multiple resizes at the same time
# BUGFIX: Version number now gets updated between versions 😛

0.1 -> 0.2

# DONE: filename.txt for file comments
# DONE: comment.txt for album comments
# DONE: Save reference to main-index thumbnail.
# DONE: Add command line option to disable EXIF block output
# BUGFIX: Now generates for all images, including the last in set.
# BUGFIX: Performs rotation according to EXIF

Todo-list

# TODO: Command line option for per-image reading of description line (filename.txt)
# TODO: Iterative generating/regen w/option. Generate only non-existant thumbs/views
# TODO: post_generate_command configuration option, to run automagically on completion.
# TODO: Stripping of image suffix for HTML file w/config option?
# TODO: Clear old generated files and meta on regen
# TODO: Image title from EXIF for a title-template-tag.
# TODO: Possibility for hide/show EXIF
# TODO: Templating of EXIF
# TODO: Priority/sorting of EXIF tags
# REQUEST: Template-tag and ID-variable for Google Analytics
# BUG:  The naive handling of filenames breaks on special characters

Lisencing

Copyright (c) 2010, Jon Langseth
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL JON LANGSETH BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.