def scale_image(image, cube_size):
    """
    Scale the input image to a whole number of cubes with minimal stretch.
    :param image: PIL Image object.
    :param cube_size: Cube size from configuration, int.
    :return: A scaled PIL Image.
    """
    image_w, image_h = image.size

    scale_h = image_h // cube_size  # Amount of cubes that fit in the height
    new_h = scale_h * cube_size

    scale_w = image_w // cube_size   # Amount of cubes that fit in the width
    new_w = scale_w * cube_size

    new_image = image.resize((new_w, new_h))  # Resize the image accordingly.
    return new_image