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

        original_width, original_height = resource.size

        resource_format = resource.format

        if self.mode == 'outbound':
            target_width, target_height = self.outbound_sizes(original_width, original_height, self.width, self.height)
            resource = resource.resize((target_width, target_height), Image.ANTIALIAS)

            crop_sizes = self.crop_sizes(target_width, target_height, self.width, self.height)
            resource = resource.crop(crop_sizes)
        else:
            target_width, target_height = self.inset_sizes(original_width, original_height, self.width, self.height)
            resource = resource.resize((target_width, target_height), Image.ANTIALIAS)

        resource.format = resource_format

        return resource