def resize_image(img, new_width):
    """Resize an image opened via PIL's Image.open().

    Maintains aspect ratio.

    Parameters
    ----------
    img : object
    new_width : int

    Returns
    -------
    object
        A PIL Image

    """

    original_width, original_height = img.size

    # Get scale factor of output img and use it to calculate the output height
    scale = new_width / original_width
    new_height = original_height * scale

    return img.resize((round(new_width), round(new_height)))