# Path: tailor/plugins/composer/filters/autocrop.py
# class Autocrop:
#     """ Crop is correctly centered.  No need to adjust or test.
# 
#     """
# 
#     def process(self, image, area):
#         # x1 = y1 = 0
#         # x2, y2 = image.size
#         # wRatio = 1.0 * x2 / area[0]
#         # hRatio = 1.0 * y2 / area[1]
#         # if hRatio > wRatio:
#         #     y1 = int(y2 / 2 - area[1] * wRatio / 2)
#         #     y2 = int(y2 / 2 + area[1] * wRatio / 2)
#         # else:
#         #     x1 = int(x2 / 2 - area[0] * hRatio / 2)
#         #     x2 = int(x2 / 2 + area[0] * hRatio / 2)
#         # image = image.crop((x1, y1, x2, y2))
#         x, y, w, h = area
#         return ImageOps.fit(image, (int(w), int(h)), Image.ANTIALIAS)


import asyncio
from PIL import Image
from .filters.autocrop import Autocrop
            lower.paste(upper, top_left, mask=upper)
        else:
            lower.paste(upper, top_left)

    def render_area_node(self, node):
        # draw = ImageDraw.Draw(self.image)
        # draw.rectangle(rect, (0, 255, 255))
        return None, None

    def render_image_node(self, node):
        # LIMITATIONS: only pastes to area, no scaling
        try:
            if node.filename is not None:
                node.data = Image.open(node.filename)
        except FileNotFoundError:
            node.data = None

        # TODO: scaling options, ect, processing chain
        if node.data is not None:
            root = node.get_root()
            area = self.convert_rect(node.parent.rect, root.dpi)
            return node.data, area

        return None, None

    def render_cropped_node(self, node):
        if node.data:
            root = node.get_root()
            # TODO: move these functions into a processing chain
            area = self.convert_rect(node.parent.rect, root.dpi)

# Path: tailor/plugins/composer/filters/autocrop.py
# class Autocrop:
#     """ Crop is correctly centered.  No need to adjust or test.
# 
#     """
# 
#     def process(self, image, area):
#         # x1 = y1 = 0
#         # x2, y2 = image.size
#         # wRatio = 1.0 * x2 / area[0]
#         # hRatio = 1.0 * y2 / area[1]
#         # if hRatio > wRatio:
#         #     y1 = int(y2 / 2 - area[1] * wRatio / 2)
#         #     y2 = int(y2 / 2 + area[1] * wRatio / 2)
#         # else:
#         #     x1 = int(x2 / 2 - area[0] * hRatio / 2)
#         #     x2 = int(x2 / 2 + area[0] * hRatio / 2)
#         # image = image.crop((x1, y1, x2, y2))
#         x, y, w, h = area
#         return ImageOps.fit(image, (int(w), int(h)), Image.ANTIALIAS)


# Path: tailor/plugins/composer/renderer.py
import asyncio
from PIL import Image
from .filters.autocrop import Autocrop

            lower.paste(upper, top_left, mask=upper)
        else:
            lower.paste(upper, top_left)

    def render_area_node(self, node):
        # draw = ImageDraw.Draw(self.image)
        # draw.rectangle(rect, (0, 255, 255))
        return None, None

    def render_image_node(self, node):
        # LIMITATIONS: only pastes to area, no scaling
        try:
            if node.filename is not None:
                node.data = Image.open(node.filename)
        except FileNotFoundError:
            node.data = None

        # TODO: scaling options, ect, processing chain
        if node.data is not None:
            root = node.get_root()
            area = self.convert_rect(node.parent.rect, root.dpi)
            return node.data, area

        return None, None

    def render_cropped_node(self, node):
        if node.data:
            root = node.get_root()
            # TODO: move these functions into a processing chain
            area = self.convert_rect(node.parent.rect, root.dpi)

            image = Autocrop().process(node.data, area)