Plugins

How to use plugins

Plugins must be specified with the plugins setting:

plugins = ['sigal.plugins.adjust', 'sigal.plugins.copyright']

You can either specify the name of the module which contains the plugin, or import the plugin before adding it to the list:

from sigal.plugins import copyright
plugins = ['sigal.plugins.adjust', copyright]

Note

Using an import like this will break the multiprocessing feature, because the settings dict must be serializable. So in most cases you should prefer the first option.

The plugin_paths setting can be used to specify paths to search for plugins (if they are not in the python path).

Write a new plugin

Plugins are based on signals with the blinker library. A plugin must subscribe to a signal (the list is given below). New signals can be added if need. See an example with the copyright plugin:

# -*- coding: utf-8 -*-

"""Plugin which add a copyright to the image.

Settings:

- ``copyright``: the copyright text.

TODO: Add more settings (font, size, ...)

"""

import logging
from PIL import ImageDraw
from sigal import signals

logger = logging.getLogger(__name__)


def add_copyright(img, settings=None):
    logger.debug('Adding copyright to %r', img)
    draw = ImageDraw.Draw(img)
    draw.text((5, img.size[1] - 15), settings['copyright'])
    return img


def register(settings):
    if settings.get('copyright'):
        signals.img_resized.connect(add_copyright)
    else:
        logger.warning('Copyright text is not set')

Signals

sigal.signals.album_initialized(album)

Called after the Album is initialized.

Parameters:album – the Album object.
sigal.signals.gallery_initialized(gallery)

Called after the gallery is initialized.

Parameters:gallery – the Gallery object.
sigal.signals.media_initialized(media)

Called after the Media (Image or Video) is initialized.

Parameters:media – the media object.
sigal.signals.gallery_build(gallery)

Called after the gallery is build (after media are resized and html files are written).

Parameters:gallery – the Gallery object.
sigal.signals.img_resized(img, settings=settings)

Called after the image is resized. This signal work differently, the modified image object must be returned by the registered funtion.

Parameters:
  • img – the PIL image object.
  • settings – the settings dict.

List of plugins

Adjust plugin

Plugin which adjust the image after resizing.

Based on pilkit’s Adjust processor.

Settings:

adjust_options = {'color': 1.0,
                  'brightness': 1.0,
                  'contrast': 1.0,
                  'sharpness': 1.0}

Copyright plugin

Plugin which add a copyright to the image.

Settings:

  • copyright: the copyright text.

TODO: Add more settings (font, size, ...)

Media page plugin

Plugin which generates HTML pages for each image.

Currently this plugin can be used only with the colorbox theme, the other themes have to be adapted.

For themes, the previous_media and next_media variables contain the previous/next Media objects.

Upload to S3 plugin

Plugin to upload generated files to Amazon S3.

This plugin requires boto. All generated files are uploaded to a specified S3 bucket. When using this plugin you have to make sure that the bucket already exists and the you have access to the S3 bucket. The access credentials are managed by boto and can be given as environment variables, configuration files etc. More information can be found on the boto documentation.

Settings (all settings are wrapped in upload_s3_options dict):

  • bucket: The to-be-used bucket for uploading.

  • policy: Specifying access control to the uploaded files. Possible values:

    private, public-read, public-read-write, authenticated-read

  • overwrite: Boolean indicating if all files should be uploaded and overwritten

    or if already uploaded files should be skipped.

  • max_age: Optional, Integer indicating the number of seconds that the cache

    control should be set by default

  • media_max_age: Optional, Integer indicates the number of seconds that

    cache control hould be set for media files

Table Of Contents

Related Topics

This Page