code: def apply(self, resource):
          
          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
docs: Apply filter to resource
          :param resource: Image
          :return: Image