- all the current Dave Pointers. - My home. A l b u m 
S e v e n   - -   P l u g i n s ,   U s a g e ,   C r e a t i o n , . . 








Mailing List  




Table Of Contents

  1. What are Plugins?
  2. Installing Plugins and plugin support
  3. Loading/Unloading Plugins
  4. Plugin Options
  5. Writing Plugins

1:   What are Plugins?

Plugins are snippets of code that allow you to modify the behavior
of album.  They can be as simple as a new way to create EXIF captions,
to something as complex as creating the album based on a database of
images instead of using the filesystem hierarchy.

2:   Installing Plugins and plugin support

There are a number of plugins available with the standard installation of
album.  If you are upgrading album with plugins from an earlier version
of album that did not have plugins (pre v3.10), you may need to once do:

% album -configure

You will not need to do this with future upgrades of album.

This will install the current plugins into one of the default
plugin directories - album will look for plugins in a number of
locations, the default locations are:


In reality, these are 'plugins' directories found in the set of
locations specified by '--data_path' - hence the defaults are:


You can specify a new location with --data_path and then add a 'plugins'
directory to that location, or use the --plugin_path option.

Plugins usually end with the ".alp" prefix, but you do not need
to specify this prefix when using plugins.  For example, if you
have a plugin installed at:


Then you would specify the plugin as:  utils/mv

3:   Loading/Unloading Plugins

To list all the currently installed plugins:

% album -list_plugins

To show information about a specific plugin (using 'utils/mv' as an example):

% album -plugin_info utils/mv

Plugins will be saved in the configuration for a given album, so
they don't need to be respecified every time (excluding one-time
plugins such as 'utils/mv')

You can use -no_plugin and -clear_plugin to turn off plugins that have
been saved in an album configuration.  As with normal album options,
-no_plugin will turn off a specific plugin, and -clear_plugin will
turn off all plugins.  Any saved plugin options for that plugin will be
erased as well.

4:   Plugin Options

A few plugins may be able to take command-line options, to view usage
for these plugins:

% album -plugin_usage utils/mv

But when specifying plugin options, you need to tell album which plugin
the option belongs to.  Instead of specifying as a normal album option:

% album -some_option

You prefix the option with the plugin name followed by a colon:

% album -some_plugin:some_option

For example, you can specify the generated 'index' created by
the 'utils/capindex' plugin.

% album -plugin utils/capindex  -utils/capindex:index blah.html

That's a bit unwieldy.  You can shorten the name of the plugin as
long as it doesn't conflict with another plugin you've loaded (by
the same name):

% album -plugin utils/capindex  -capindex:index

Obviously the other types of options (strings, numbers and arrays) are
possible and use the same convention.  They are saved in album configuration
the same as normal album options.

One caveat:  As mentioned, once we use a plugin on an album it is saved
in the configuration.  If you want to add options to an album that is
already configured to use a plugin, you either need to mention the plugin
again, or else use the full name when specifying the options (otherwise
we won't know what the shortened option belongs to).

For example, consider an imaginary plugin:

% album -plugin some/example/thumbGen Photos/Spain

After that, let's say we want to use the thumbGen boolean option "fast".
This will not work:

% album -thumbGen:fast Photos/Spain

But either of these will work:

% album -plugin some/example/thumbGen -thumbGen:fast blah.html Photos/Spain
% album -some/example/thumbGen:fast Photos/Spain

5:   Writing Plugins

Plugins are small perl modules that register "hooks" into the album code.

There are hooks for most of the album functionality, and the plugin hook
code can often either replace or supplement the album code.  More hooks
may be added to future versions of album as needed.

You can see a list of all the hooks that album allows:

% album -list_hooks

And you can get specific information about a hook:

% album -hook_info <hook_name>

We can use album to generate our plugin framework for us:

% album -create_plugin

For this to work, you need to understand album hooks and album options.

We can also write the plugin by hand, it helps to use an already
written plugin as a base to work off of.

In our plugin we register the hook by calling the album::hook() function.
To call functions in the album code, we use the album namespace.
As an example, to register code for the clean_name hook our plugin calls:


Then whenever album does a clean_name it will also call the plugin
subroutine called my_clean (which we need to provide).

To write my_clean let's look at the clean_name hook info:

  Args: ($opt, 'clean_name',  $name, $iscaption)
  Description: Clean a filename for printing.
    The name is either the filename or comes from the caption file.
  Returns: Clean name

The args that the my_clean subroutine get are specified on the first line.
Let's say we want to convert all names to uppercase.  We could use:

sub my_clean {
  my ($opt, $hookname, $name, $iscaption) = @_;
  return uc($name);

Here's an explanation of the arguments:

$opt        This is the handle to all of album's options.
            We didn't use it here.  Sometimes you'll need it if you
            call any of albums internal functions.  This is also true
            if a $data argument is supplied.
$hookname   In this case it will be 'clean_name'.  This allows us
            to register the same subroutine to handle different hooks.
$name       This is the name we are going to clean.
$iscaption  This tells us whether the name came from a caption file.
            To understand any of the options after the $hookname you
            may need to look at the corresponding code in album.

In this case we only needed to use the supplied $name, we called
the perl uppercase routine and returned that.  The code is done, but now
we need to create the plugin framework.

Some hooks allow you to replace the album code.  For example, you
could write plugin code that can generate thumbnails for pdf files
(using 'convert' is one way to do this).  We can register code for
the 'thumbnail' hook, and just return 'undef' if we aren't looking
at a pdf file, but when we see a pdf file, we create a thumbnail
and then return that.  When album gets back a thumbnail, then it
will use that and skip it's own thumbnail code.

Now let's finish writing our uppercase plugin.  A plugin must do the following:

1) Supply a 'start_plugin' routine.  This is where you will likely
   register hooks and specify any command-line options for the plugin.

2) The 'start_plugin' routine must return the plugin info
   hash, which needs the following keys defined:
   author      => The author name
   href        => A URL (or mailto, of course) for the author
   version     => Version number for this plugin
   description => Text description of the plugin

3) End the plugin code by returning '1' (similar to a perl module).

Here is our example clean_name plugin code in a complete plugin:

sub start_plugin { my ($opt) = @_; album::hook($opt,'clean_name',\&my_clean); return { author => 'David Ljung Madison', href => '', version => '1.0', description => "Conver image names to uppercase", }; } sub my_clean { return uc($name); } 1;
Finally, we need to save this somewhere. Plugins are organized in the plugin directory hierarchy, we could save this in a plugin directory as: captions/formatting/NAME.alp In fact, if you look in examples/formatting/NAME.alp you'll find that there's a plugin already there that does essentially the same thing. If you want your plugin to accept command-line options, use 'add_option.' This must be done in the start_plugin code. Some examples: album::add_option(1,"fast",album::OPTION_BOOL, usage=>"Do it fast"); album::add_option(1,"name", album::OPTION_STR, usage=>"Your name"); album::add_option(1,"colors",album::OPTION_ARR, usage=>"Color list"); For more info, see the 'add_option' code in album and see all of the uses of it (at the top of album and in plugins that use 'add_option') To read an option that the user may have set, we use option(): my $fast = album::option($opt, "fast"); If the user gave a bad value for an option, you can call usage(): album::usage("-colors array can only include values [red, green, blue]"); If your plugin needs to load modules that are not part of the standard Perl distribution, please do this conditionally. For an example of this, see plugins/extra/rss.alp. You can also call any of the routines found in the album script using the album:: namespace. Make sure you know what you are doing. Some useful routines are: album::add_head($opt,$data, "<meta name='add_this' content='to the <head>'>"); album::add_header($opt,$data, "<p>This gets added to the album header"); album::add_footer($opt,$data, "<p>This gets added to the album footer"); The best way to figure out how to write plugins is to look at other plugins, possibly copying one that is similar to yours and working off of that. Plugin development tools may be created in the future. Again, album can help create the plugin framework for you: % album -create_plugin

  • Created by make_faq from Marginal Hacks