def apply(self, resource):
        """
        Apply filter to resource
        :param resource: Image.Image
        :return: Image.Image
        """
        if not isinstance(resource, Image.Image):
            raise ValueError('Unknown resource format')

        resource_format = resource.format
        if resource.mode != 'RGBA':  # pragma: no cover
            resource = resource.convert('RGBA')

        layer = Image.new('RGBA', resource.size, (0, 0, 0, 0))
        image, left, upper = getattr(self, '_' + self.position + '_position')(resource)
        layer.paste(image, (left, upper))

        image = Image.composite(layer, resource, layer)
        image.format = resource_format

        return image
def apply ( self , resource ) : if not isinstance ( resource , Image . Image ) : raise ValueError ( 'Unknown resource format' ) resource_format = resource . format if resource . mode != 'RGBA' : resource = resource . convert ( 'RGBA' ) layer = Image . new ( 'RGBA' , resource . size , ( 0 , 0 , 0 , 0 ) ) image , left , upper = getattr ( self , '_' + self . position + '_position' ) ( resource ) layer . paste ( image , ( left , upper ) ) image = Image . composite ( layer , resource , layer ) image . format = resource_format return image
Apply filter to resource
        :param resource: Image.Image
        :return: Image.Image