def calculate_bounding_box_from_image(im, curr_page):
    """This function uses a PIL routine to get the bounding box of the rendered
    image."""
    xMax, y_max = im.size
    bounding_box = im.getbbox()
    if not bounding_box:
        bounding_box = xMax / 2, y_max / 2, xMax / 2, y_max / 2
    bounding_box = list(bounding_box)
    bounding_box[1] = y_max - bounding_box[1]
    bounding_box[3] = y_max - bounding_box[3]
    full_page_box = curr_page.mediaBox
    convert_x = float(full_page_box.getUpperRight_x() - full_page_box.
        getLowerLeft_x()) / xMax
    convert_y = float(full_page_box.getUpperRight_y() - full_page_box.
        getLowerLeft_y()) / y_max
    final_box = [bounding_box[0] * convert_x, bounding_box[3] * convert_y, 
        bounding_box[2] * convert_x, bounding_box[1] * convert_y]
    return final_box
