def crop_image_to_square(img):
  """Crops image to the largest square that fits inside img.

  Crops from the top left corner.

  Args:
    img: image of type PIL image, e.g. PIL.JpegImagePlugin.JpegImageFile.

  Returns:
    Square image of same type as input image.
  """
  side_length = min(img.height, img.width)
  return img.crop((0, 0, side_length, side_length))