class_docstr: Create a sphinx gallery thumbnail for insertion anywhere in docs.
  Optionally, you can specify the custom figure and intro/tooltip for the
  thumbnail.
  Example usage:
  .. galleryitem:: intermediate/char_rnn_generation_tutorial.py
      :figure: _static/img/char_rnn_generation.png
      :intro: Put your custom intro here.
  If figure is specified, a thumbnail will be made out of it and stored in
  _static/thumbs. Therefore, consider _static/thumbs as a 'built' directory.
class_docstr_tok: ["Create","a","sphinx","gallery","thumbnail","for","insertion","anywhere","in","docs",".","Optionally",",","you","can","specify","the","custom","figure","and","intro\/tooltip","for","the","thumbnail",".","Example","usage",":","..","galleryitem",":",":","intermediate\/char_rnn_generation_tutorial.py",":","figure",":","_static\/img\/char_rnn_generation.png",":","intro",":","Put","your","custom","intro","here",".","If","figure","is","specified",",","a","thumbnail","will","be","made","out","of","it","and","stored","in","_static\/thumbs",".","Therefore",",","consider","_static\/thumbs","as","a","'built","'","directory","."]
code: def run(self):
      args = self.arguments
      fname = args[-1]
  
      env = self.state.document.settings.env
      fname, abs_fname = env.relfn2path(fname)
      basename = os.path.basename(fname)
      dirname = os.path.dirname(fname)
  
      try:
          if "intro" in self.options:
              intro = self.options["intro"][:195] + "..."
          else:
              intro = sphinx_gallery.gen_rst.extract_intro(abs_fname)
  
          thumbnail_rst = sphinx_gallery.backreferences._thumbnail_div(
              dirname, basename, intro
          )
  
          if "figure" in self.options:
              rel_figname, figname = env.relfn2path(
                  self.options["figure"]
              )
              save_figname = os.path.join(
                  "_static/thumbs/", os.path.basename(figname)
              )
  
              try:
                  os.makedirs("_static/thumbs")
              except OSError:
                  pass
  
              sphinx_gallery.gen_rst.scale_image(
                  figname, save_figname, 400, 280
              )
              # replace figure in rst with simple regex
              thumbnail_rst = re.sub(
                  r"..\sfigure::\s.*\.png",
                  ".. figure:: /{}".format(save_figname),
                  thumbnail_rst,
              )
  
          thumbnail = StringList(thumbnail_rst.split("\n"))
          thumb = nodes.paragraph()
          self.state.nested_parse(thumbnail, self.content_offset, thumb)
  
          return [thumb]
      except FileNotFoundError as e:
          print(e)
          return []
  
file_path: mlens/docs/source/custom_directives.py
imports: from docutils.parsers.rst import Directive, directives
  from docutils.statemachine import StringList
  from docutils import nodes
  import re
  import os
  import sphinx_gallery
label_desc: Use image node_id 1 for calling the GalleryItemDirective obj's underlying member method code with example usage: obj.run() and returns: list, list