mirror of https://github.com/saimn/sigal.git
14 changed files with 228 additions and 33 deletions
@ -0,0 +1,86 @@
|
||||
========= |
||||
Plugins |
||||
========= |
||||
|
||||
How to use plugins |
||||
------------------ |
||||
|
||||
Plugins must be specified with the ``plugins`` setting: |
||||
|
||||
.. code-block:: python |
||||
|
||||
from sigal.plugins import copyright |
||||
plugins = ['sigal.plugins.adjust', copyright] |
||||
|
||||
You can either specify the name of the module which contains the plugin, or |
||||
import the plugin before adding it to the list. 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: |
||||
|
||||
.. _blinker: http://pythonhosted.org/blinker/ |
||||
|
||||
.. literalinclude:: ../sigal/plugins/copyright.py |
||||
:language: python |
||||
|
||||
Signals |
||||
------- |
||||
|
||||
.. function:: sigal.signals.album_initialized(album) |
||||
:noindex: |
||||
|
||||
Called after the :class:`~sigal.gallery.Album` is initialized. |
||||
|
||||
:param album: the :class:`~sigal.gallery.Album` object. |
||||
|
||||
.. data:: sigal.signals.gallery_initialized(gallery) |
||||
:noindex: |
||||
|
||||
Called after the gallery is initialized. |
||||
|
||||
:param gallery: the :class:`Gallery` object. |
||||
|
||||
.. data:: sigal.signals.media_initialized(media) |
||||
:noindex: |
||||
|
||||
Called after the :class:`~sigal.gallery.Media` |
||||
(:class:`~sigal.gallery.Image` or :class:`~sigal.gallery.Video`) is |
||||
initialized. |
||||
|
||||
:param media: the media object. |
||||
|
||||
.. data:: sigal.signals.gallery_build(gallery) |
||||
:noindex: |
||||
|
||||
Called after the gallery is build (after media are resized and html files |
||||
are written). |
||||
|
||||
:param gallery: the :class:`Gallery` object. |
||||
|
||||
.. data:: sigal.signals.img_resized(img, settings=settings) |
||||
:noindex: |
||||
|
||||
Called after the image is resized. This signal work differently, the |
||||
modified image object must be returned by the registered funtion. |
||||
|
||||
:param img: the PIL image object. |
||||
:param settings: the settings dict. |
||||
|
||||
List of plugins |
||||
--------------- |
||||
|
||||
Adjust plugin |
||||
============= |
||||
|
||||
.. automodule:: sigal.plugins.adjust |
||||
|
||||
Copyright plugin |
||||
================ |
||||
|
||||
.. automodule:: sigal.plugins.copyright |
||||
@ -0,0 +1,34 @@
|
||||
# -*- coding: utf-8 -*- |
||||
|
||||
"""Plugin which adjust the image after resizing. |
||||
|
||||
Based on pilkit's Adjust_ processor. |
||||
|
||||
.. _Adjust: https://github.com/matthewwithanm/pilkit/blob/master/pilkit/processors/base.py#L19 |
||||
|
||||
Settings:: |
||||
|
||||
adjust_options = {'color': 1.0, |
||||
'brightness': 1.0, |
||||
'contrast': 1.0, |
||||
'sharpness': 1.0} |
||||
|
||||
""" |
||||
|
||||
import logging |
||||
from sigal import signals |
||||
from pilkit.processors import Adjust |
||||
|
||||
logger = logging.getLogger(__name__) |
||||
|
||||
|
||||
def adjust(img, settings=None): |
||||
logger.debug('Adjust image %r', img) |
||||
return Adjust(**settings['adjust_options']).process(img) |
||||
|
||||
|
||||
def register(settings): |
||||
if settings.get('adjust_options'): |
||||
signals.img_resized.connect(adjust) |
||||
else: |
||||
logger.warning('Adjust options are not set') |
||||
@ -0,0 +1,31 @@
|
||||
# -*- 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') |
||||
@ -0,0 +1,10 @@
|
||||
# -*- coding: utf-8 -*- |
||||
|
||||
from blinker import signal |
||||
|
||||
img_resized = signal('img_resized') |
||||
|
||||
album_initialized = signal('album_initialized') |
||||
gallery_initialized = signal('gallery_initialized') |
||||
gallery_build = signal('gallery_build') |
||||
media_initialized = signal('media_initialized') |
||||
Loading…
Reference in new issue