def export_as_image():
    """Export loaded file as .html/.svg or .png file.

    The current state of the file is exported, that is,
    the objects currently alive, regardless of whether
    they are saved or not in the disk.
    """
    ###
    gm = APP_REFS.gm

    ### if there are no live objects at all in the
    ### file, notify user via dialog and cancel
    ### operation by returning earlier

    if not gm.nodes and not gm.text_blocks:

        create_and_show_dialog(
            (
                "To export the loaded file as an image there"
                " must exist at least one live object in it"
            ),
            level_name='info',
        )

        return

    ### reference instance of a rects manager that controls the
    ### position of all objects in the loaded file
    all_rectsman = gm.rectsman

    ### store the size of the resulting rects manager
    size = all_rectsman.size

    ### prompt user for image exporting settings
    ### (passing along the total size occupied by
    ### the objects in the loaded file as additional
    ### info to be displayed to the user)
    settings = get_image_exporting_settings(size)

    ### if the settings received are actually None,
    ### it means the user cancelled the operation,
    ### so we exit the method by returning
    if settings is None:
        return

    ### otherwise we proceed with the image exporting
    ### operation...

    ### let's measure the time taken to export the
    ### image
    start = time()

    ### backup the topleft
    original_topleft = all_rectsman.topleft

    ### move objects' topleft to the given margins

    all_rectsman.topleft = (
        settings.pop("horizontal_margin"),
        settings.pop("vertical_margin"),
    )

    ### obtain a pathlib.Path version of the image path
    image_path = Path(settings["image_path"])

    ### retrieve the extension
    extension = image_path.suffix.lower()

    ### pick image exporting method according to the
    ### file format

    if extension == ".png":
        export_method = export_file_as_png

    elif extension == ".svg":
        export_method = export_file_as_svg

    elif extension == ".html":
        export_method = export_file_as_html

    ### try creating and saving image

    try:
        export_method(**settings)

    except Exception as err:

        ## log traceback in regular
        ## log and and user log

        error_message = (
            "An unexpected error ocurred"
            " while trying to export node"
            f" layout as {extension}."
        )

        logger.exception(error_message)
        USER_LOGGER.exception(error_message)

    else:
        error_message = ''

    ### then restore the objects to their original
    ### positions
    all_rectsman.topleft = original_topleft

    ### store the total time taken to execute the
    ### operations above
    total = time() - start

    ### if there was an error (there is an error messsage),
    ### notify the user via a dialog

    if error_message:

        dialog_message = error_message + (
            " Check the user log for more info (on the graph/canvas, press"
            " <Ctrl+Shift+j> or access the \"Help > Show user log\" option"
            " on the menubar)."
        )

        create_and_show_dialog(dialog_message, level_name='error')

    ### otherwise just display a message in the
    ### statusbar, showing the time taken in a
    ### friendly format

    else:

        message = ("File exported as '{}' image in {}").format(
            image_path.name, friendly_delta_from_secs(total)
        )

        set_status_message(message)
Export loaded file as .html/.svg or .png file.

    The current state of the file is exported, that is,
    the objects currently alive, regardless of whether
    they are saved or not in the disk.
    
nodezator/editing/imageexport/main.py