def prepare_image(
    img,
    max_size=(1080, 1350),
    aspect_ratios=(4.0 / 5.0, 90.0 / 47.0),
    save_path=None,
    **kwargs
):
    """
    Prepares an image file for posting.
    Defaults for size and aspect ratio from https://help.instagram.com/1469029763400082

    :param img: file path
    :param max_size: tuple of (max_width,  max_height)
    :param aspect_ratios: single float value or tuple of (min_ratio, max_ratio)
    :param save_path: optional output file path
    :param kwargs:
             - **min_size**: tuple of (min_width,  min_height)
    :return:
    """
    min_size = kwargs.pop("min_size", (320, 167))
    if is_remote(img):
        res = requests.get(img, timeout=5)
        im = Image.open(io.BytesIO(res.content))
    else:
        im = Image.open(img)

    if aspect_ratios:
        crop_box = calc_crop(aspect_ratios, im.size)
        if crop_box:
            im = im.crop(crop_box)

    new_size = calc_resize(max_size, im.size, min_size=min_size)
    if new_size:
        im = im.resize(new_size)

    if im.mode != "RGB":
        # Removes transparency (alpha)
        im = im.convert("RGBA")
        im2 = Image.new("RGB", im.size, (255, 255, 255))
        im2.paste(im, (0, 0), im)
        im = im2
    if save_path:
        im.save(save_path)

    b = io.BytesIO()
    im.save(b, "JPEG")
    return b.getvalue(), im.size

    Prepares an image file for posting.
    Defaults for size and aspect ratio from https://help.instagram.com/1469029763400082

    :param img: file path
    :param max_size: tuple of (max_width,  max_height)
    :param aspect_ratios: single float value or tuple of (min_ratio, max_ratio)
    :param save_path: optional output file path
    :param kwargs:
             - **min_size**: tuple of (min_width,  min_height)
    :return:
    
instagrapi/image_util.py