mirror of https://github.com/saimn/sigal.git
9 changed files with 138 additions and 20 deletions
@ -0,0 +1,29 @@
|
||||
========= |
||||
Plugins |
||||
========= |
||||
|
||||
Signals |
||||
------- |
||||
|
||||
.. data:: sigal.signals.img_resized |
||||
:noindex: |
||||
|
||||
Called after the image is resized. |
||||
|
||||
Write a new plugin |
||||
------------------ |
||||
|
||||
See an example with the copyright plugin: |
||||
|
||||
.. literalinclude:: ../sigal/plugins/copyright.py |
||||
:language: python |
||||
|
||||
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') |
||||
Loading…
Reference in new issue