def METHOD_NAME(flow_graph, file_path, transparent_bg=False):
    if not file_path:
        return
    x_min, y_min, x_max, y_max = flow_graph.get_extents()
    padding = Constants.CANVAS_GRID_SIZE
    width = x_max - x_min + 2 * padding
    height = y_max - y_min + 2 * padding
    if file_path.endswith('.png'):
        # ImageSurface is pixel-based, so dimensions need to be integers
        # We don't round up here, because our padding should allow for up
        # to half a pixel size in loss of image area without optically bad
        # effects
        psurf = cairo.ImageSurface(cairo.FORMAT_ARGB32,
                                   round(width),
                                   round(height))
    elif file_path.endswith('.pdf'):
        psurf = cairo.PDFSurface(file_path, width, height)
    elif file_path.endswith('.svg'):
        psurf = cairo.SVGSurface(file_path, width, height)
    else:
        raise ValueError('Unknown file format')
    cr = cairo.Context(psurf)
    if not transparent_bg:
        cr.set_source_rgba(*FLOWGRAPH_BACKGROUND_COLOR)
        cr.rectangle(0, 0, width, height)
        cr.fill()
    cr.translate(padding - x_min, padding - y_min)
    flow_graph.create_labels(cr)
    flow_graph.create_shapes()
    flow_graph.draw(cr)
    if file_path.endswith('.png'):
        psurf.write_to_png(file_path)
    if file_path.endswith('.pdf') or file_path.endswith('.svg'):
        cr.show_page()
    psurf.finish()