code: def _thumbnail_div(full_dir, fname, snippet, is_backref=False):
      """Generates RST to place a thumbnail in a gallery"""
      thumb = os.path.join(
          full_dir,
          "images",
          "thumb",
          "sphx_glr_%s_thumb.png" % fname[:-3],
      )
  
      # Inside rst files forward slash defines paths
      thumb = thumb.replace(os.sep, "/")
  
      ref_name = os.path.join(full_dir, fname).replace(os.path.sep, "_")
  
      template = (
          BACKREF_THUMBNAIL_TEMPLATE
          if is_backref
          else THUMBNAIL_TEMPLATE
      )
      return template.format(
          snippet=escape(snippet), thumbnail=thumb, ref_name=ref_name
      )
  
file_path: tensorly/doc/sphinx_ext/sphinx_gallery/backreferences.py
imports: from __future__ import print_function
  import ast
  import os
label_desc: Use image node_id 4 for calling a global function with example usage: _thumbnail_div(full_dir, fname, snippet, is_backref) and returns: template