code: def convert(filename, cache):
      """
      Convert the named file to png; return the name of the created file.
  
      If *cache* is True, the result of the conversion is cached in
      `matplotlib.get_cachedir() + '/test_cache/'`.  The caching is based on a
      hash of the exact contents of the input file.  Old cache entries are
      automatically deleted as needed to keep the size of the cache capped to
      twice the size of all baseline images.
      """
      path = Path(filename)
      if not path.exists():
          raise OSError(f"{path} does not exist")
      if path.suffix[1:] not in converter:
          import pytest
  
          pytest.skip(
              f"Don't know how to convert {path.suffix} files to png"
          )
      newpath = path.parent / f"{path.stem}_{path.suffix[1:]}.png"
  
      # Only convert the file if the destination doesn't already exist or
      # is out of date.
      if (
          not newpath.exists()
          or newpath.stat().st_mtime < path.stat().st_mtime
      ):
          cache_dir = _get_cache_path() if cache else None
  
          if cache_dir is not None:
              _register_conversion_cache_cleaner_once()
              hash_value = get_file_hash(path)
              cached_path = cache_dir / (hash_value + newpath.suffix)
              if cached_path.exists():
                  _log.debug(
                      "For %s: reusing cached conversion.", filename
                  )
                  shutil.copyfile(cached_path, newpath)
                  return str(newpath)
  
          _log.debug("For %s: converting to png.", filename)
          convert = converter[path.suffix[1:]]
          if path.suffix == ".svg":
              contents = path.read_text()
              if 'style="font:' in contents:
                  # for svg.fonttype = none, we explicitly patch the font search
                  # path so that fonts shipped by Matplotlib are found.
                  convert = _svg_with_matplotlib_fonts_converter
          convert(path, newpath)
  
          if cache_dir is not None:
              _log.debug("For %s: caching conversion result.", filename)
              shutil.copyfile(newpath, cached_path)
  
      return str(newpath)
  
imports: import atexit
  import functools
  import hashlib
  import logging
  import os
  from pathlib import Path
  import shutil
  import subprocess
  import sys
  from tempfile import TemporaryDirectory, TemporaryFile
  import weakref
  import numpy
  from PIL import Image
  import matplotlib
  from matplotlib import cbook
  from matplotlib.testing.exceptions import ImageComparisonFailure
label_desc: Use image node_id 7 for calling a global function with example usage: convert(filename, cache) and returns: str, str