def export_file_as_png(width, height, background_color, image_path):
    """Export loaded file as an .png image file.

    That is, the current state of the file is exported,
    the objects currently alive, regardless of whether
    they are saved on disk.
    """
    ### create a new surface according to the color
    ### picked and image file format

    ## pick surface conversion method according to
    ## whether the color has alpha (transparency)

    try:
        alpha = background_color[3]

    except IndexError:
        conversion_method = Surface.convert

    else:

        conversion_method = (
            Surface.convert if alpha == 255 else Surface.convert_alpha
        )

    ## create the surface using the appropriate
    ## conversion method
    surf = conversion_method(Surface((width, height)))

    ## fill surface with chosen color
    surf.fill(background_color)

    ###
    gm = APP_REFS.gm

    ### draw objects on the surface we just created

    ## preview objects

    for obj in chain(
        gm.preview_panels,
        gm.preview_toolbars,
    ):
        obj.draw_on_surf(surf)

    ## lines
    gm.draw_lines_on_surf(surf)

    ## nodes

    for node in gm.nodes:
        node.draw_on_surf(surf)

    ## text blocks
    gm.text_blocks.draw_on_surf(surf)

    ### then save the image in the given path
    save_image(surf, image_path)
Export loaded file as an .png image file.

    That is, the current state of the file is exported,
    the objects currently alive, regardless of whether
    they are saved on disk.
    
nodezator/editing/imageexport/main.py