code: def graphviz_to_file(g, filename, format):
      fmts = [".png", ".pdf", ".dot", ".svg", ".jpeg", ".jpg"]
  
      if (
          format is None
          and filename is not None
          and any(filename.lower().endswith(fmt) for fmt in fmts)
      ):
          filename, format = os.path.splitext(filename)
          format = format[1:].lower()
  
      if format is None:
          format = "png"
  
      data = g.pipe(format=format)
      if not data:
          raise RuntimeError(
              "Graphviz failed to properly produce an image. "
              "This probably means your installation of graphviz "
              "is missing png support. See: "
              "https://github.com/ContinuumIO/anaconda-issues/"
              "issues/485 for more information."
          )
  
      display_cls = _get_display_cls(format)
  
      if filename is None:
          return display_cls(data=data)
  
      full_filename = ".".join([filename, format])
      with open(full_filename, "wb") as f:
          f.write(data)
  
      return display_cls(filename=full_filename)
  
file_path: dask/dask/dot.py
imports: from __future__ import annotations
  import os
  import re
  from functools import partial
  from dask.core import get_dependencies, ishashable, istask
  from dask.utils import apply, funcname, import_required, key_split
label_desc: Use image node_id 9 for calling a global function with example usage: graphviz_to_file(g, filename, format) and returns: display_cls, display_cls