in data/conceptual_captions/generate_conceptual_caption.py [0:0]
def resize_image(image: PIL.Image) -> PIL.Image:
"""
Resize a single image to have the bigger size at most 352 pixels while maintaining aspect ratio.
Remove metadata from the image.
Args:
image (PIL.Image): The image to be resized.
Returns:
PIL.Image: The resized image without metadata.
"""
# Resize so that the bigger size is at most 352
width, height = image.size
if width > height:
new_width = 352
new_height = int(height * 352 / width)
else:
new_height = 352
new_width = int(width * 352 / height)
image = image.resize((new_width, new_height), PIL.Image.BILINEAR)
image = image.convert("RGB") # Make sure the image is RGB
data = list(image.getdata()) # Get only the image data, and place it in a new image to remove metadata
image_without_exif = PIL.Image.new(image.mode, image.size)
image_without_exif.putdata(data)
return image_without_exif