'Rescales and crops the image to the given dimensions preserving
aspect::
(w_in / h_in) = (w_scaled / h_scaled)
w_scaled = max(w_out, h_out * (w_in / h_in))
h_scaled = max(h_out, w_out * (h_in / w_in))
Args:
max_width: The largest possible width.
max_height: The larget possible height.'

def crop(self, output_path, width, height, output_type):

    if ((width * self.height) > (height * self.width)):
        scaled_height = ((width * self.height) // self.width)
        scaled_image = self.image.resize((width, scaled_height), Image.ANTIALIAS)
        crop_top = ((scaled_height - height) // 2)
        crop_bottom = (height + crop_top)
        cropped = scaled_image.crop((0, crop_top, width, crop_bottom))
    else:
        scaled_width = ((height * self.width) // self.height)
        scaled_image = self.image.resize((scaled_width, height), Image.ANTIALIAS)
        crop_left = ((scaled_width - width) // 2)
        crop_right = (width + crop_left)
        cropped = scaled_image.crop((crop_left, 0, crop_right, height))
    return self.save_image(cropped, output_type, output_path)
