# Path: pyrikura/ipyrikura.py
# class IPyrikuraPlugin(Interface):
# class ITrigger(Interface):
# class IImageProcessor(Interface):
# class IFileOp(Interface):
# class ICamera(Interface):
#     def trigger(self):
#     def process(self):
#     def process(self):


from twisted.plugin import IPlugin
from twisted.internet import threads
from zope.interface import implements
from pyrikura import ipyrikura
from PIL import Image



class ImageThumb(object):
    """
    simple thumbnailer.

    spawns a thread that launches a childprocess that resizes the image.
    creates a square crop to the size passed
    """
    implements(ipyrikura.IFileOp)

    def __init__(self, size, destination):
        self.size = size
        self.destination = destination

    def thumbnail(self, filename):
        image = Image.open(filename)
        image.thumbnail(self.size)
        image.save(self.destination)
        return self.destination

    def process(self, filename):
        if filename is None:
            raise ValueError
        return threads.deferToThread(self.thumbnail, filename)


class ImageThumbFactory(object):

# Path: pyrikura/ipyrikura.py
# class IPyrikuraPlugin(Interface):
# class ITrigger(Interface):
# class IImageProcessor(Interface):
# class IFileOp(Interface):
# class ICamera(Interface):
#     def trigger(self):
#     def process(self):
#     def process(self):


# Path: pyrikura/twisted/plugins/imagethumb.py
from twisted.plugin import IPlugin
from twisted.internet import threads
from zope.interface import implements
from pyrikura import ipyrikura
from PIL import Image




class ImageThumb(object):
    """
    simple thumbnailer.

    spawns a thread that launches a childprocess that resizes the image.
    creates a square crop to the size passed
    """
    implements(ipyrikura.IFileOp)

    def __init__(self, size, destination):
        self.size = size
        self.destination = destination

    def thumbnail(self, filename):
        image = Image.open(filename)
        image.thumbnail(self.size)
        image.save(self.destination)
        return self.destination

    def process(self, filename):
        if filename is None:
            raise ValueError
        return threads.deferToThread(self.thumbnail, filename)


class ImageThumbFactory(object):

    implements(IPlugin, ipyrikura.IPyrikuraPlugin)