# Path: sigal/signals.py



import logging
from PIL import Image, ImageEnhance
from sigal import signals
    layer = Image.new('RGBA', im.size, (0, 0, 0, 0))
    if position == 'tile':
        for y in range(0, im.size[1], mark.size[1]):
            for x in range(0, im.size[0], mark.size[0]):
                layer.paste(mark, (x, y))
    elif position == 'scale':
        # scale, but preserve the aspect ratio
        ratio = min(float(im.size[0]) / mark.size[0], float(im.size[1]) / mark.size[1])
        w = int(mark.size[0] * ratio)
        h = int(mark.size[1] * ratio)
        mark = mark.resize((w, h))
        layer.paste(mark, (int((im.size[0] - w) / 2), int((im.size[1] - h) / 2)))
    else:
        layer.paste(mark, position)
    # composite the watermark with the layer
    return Image.composite(layer, im, layer)


def add_watermark(img, settings=None):
    logger = logging.getLogger(__name__)
    logger.debug('Adding watermark to %r', img)
    mark = Image.open(settings['watermark'])
    position = settings.get('watermark_position', 'scale')
    opacity = settings.get("watermark_opacity", 1)
    return watermark(img, mark, position, opacity)


def register(settings):
    logger = logging.getLogger(__name__)
    if settings.get('watermark'):

# Path: sigal/signals.py



# Path: sigal/plugins/watermark.py
import logging
from PIL import Image, ImageEnhance
from sigal import signals

    layer = Image.new('RGBA', im.size, (0, 0, 0, 0))
    if position == 'tile':
        for y in range(0, im.size[1], mark.size[1]):
            for x in range(0, im.size[0], mark.size[0]):
                layer.paste(mark, (x, y))
    elif position == 'scale':
        # scale, but preserve the aspect ratio
        ratio = min(float(im.size[0]) / mark.size[0], float(im.size[1]) / mark.size[1])
        w = int(mark.size[0] * ratio)
        h = int(mark.size[1] * ratio)
        mark = mark.resize((w, h))
        layer.paste(mark, (int((im.size[0] - w) / 2), int((im.size[1] - h) / 2)))
    else:
        layer.paste(mark, position)
    # composite the watermark with the layer
    return Image.composite(layer, im, layer)


def add_watermark(img, settings=None):
    logger = logging.getLogger(__name__)
    logger.debug('Adding watermark to %r', img)
    mark = Image.open(settings['watermark'])
    position = settings.get('watermark_position', 'scale')
    opacity = settings.get("watermark_opacity", 1)
    return watermark(img, mark, position, opacity)


def register(settings):
    logger = logging.getLogger(__name__)
    if settings.get('watermark'):

        signals.img_resized.connect(add_watermark)