<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def savefig( filename, width=None, height=None, fig=None, timeout_seconds=10, output_widget=None, headless=False, devmode=False ):
 """Save the figure to an image file. :param str filename: must have extension .png, .jpeg or .svg :param int width: the width of the image in pixels :param int height: the height of the image in pixels :type fig: ipyvolume.widgets.Figure or None :param fig: if None use the current figure :param float timeout_seconds: maximum time to wait for image data to return :param ipywidgets.Output output_widget: a widget to use as a context manager for capturing the data :param bool headless: if True, use headless chrome to save figure :param bool devmode: if True, attempt to get index.js from local js/dist folder """

    __, ext = os.path.splitext(filename)
    format = ext[1:]
    assert format in ['png', 'jpeg', 'svg'], "image format must be png, jpeg or svg"
    with open(filename, "wb") as f:
        f.write(
            _screenshot_data(
                timeout_seconds=timeout_seconds,
                output_widget=output_widget,
                format=format,
                width=width,
                height=height,
                fig=fig,
                headless=headless,
                devmode=devmode,
            )
        )