class_docstr: An embedded IPython instance to run inside Sphinx
docstr: # build out an image directive like
  # .. image:: somefile.png
  #    :width 4in
  #
  # from an input like
  # savefig somefile.png width=4in
docstr_tok: ["#","build","out","an","image","directive","like","#","..","image",":",":","somefile.png","#",":","width","4in","#","#","from","an","input","like","#","savefig","somefile.png","width=4in"]
code: def process_image(self, decorator):
      """
      # build out an image directive like
      # .. image:: somefile.png
      #    :width 4in
      #
      # from an input like
      # savefig somefile.png width=4in
      """
      savefig_dir = self.savefig_dir
      source_dir = self.source_dir
      saveargs = decorator.split(" ")
      filename = saveargs[1]
      # insert relative path to image file in source
      # as absolute path for Sphinx
      # sphinx expects a posix path, even on Windows
      path = pathlib.Path(savefig_dir, filename)
      outfile = "/" + path.relative_to(source_dir).as_posix()
  
      imagerows = [".. image:: %s" % outfile]
  
      for kwarg in saveargs[2:]:
          arg, val = kwarg.split("=")
          arg = arg.strip()
          val = val.strip()
          imagerows.append("   :%s: %s" % (arg, val))
  
      image_file = os.path.basename(outfile)  # only return file name
      image_directive = "\n".join(imagerows)
      return image_file, image_directive
  
imports: import atexit
  import errno
  import os
  import pathlib
  import re
  import sys
  import tempfile
  import ast
  import warnings
  import shutil
  from io import StringIO
  from docutils.parsers.rst import directives
  from docutils.parsers.rst import Directive
  from sphinx.util import logging
  from traitlets.config import Config
  from IPython import InteractiveShell
  from IPython.core.profiledir import ProfileDir
label_desc: Use image node_id 6 for calling the EmbeddedSphinxShell obj's underlying member method code with example usage: obj.process_image(decorator) and returns: image_file,  image_directive