code: def save_thumbnail(image_path_template, src_file, file_conf, gallery_conf):
      
      # read specification of the figure to display as thumbnail from main text
      thumbnail_number = file_conf.get('thumbnail_number', 1)
      if not isinstance(thumbnail_number, int):
          raise TypeError(
              'sphinx_gallery_thumbnail_number setting is not a number, '
              'got %r' % (thumbnail_number,))
      thumbnail_image_path, ext = _find_image_ext(image_path_template,
                                                  thumbnail_number)
  
      thumb_dir = os.path.join(os.path.dirname(thumbnail_image_path), 'thumb')
      if not os.path.exists(thumb_dir):
          os.makedirs(thumb_dir)
  
      base_image_name = os.path.splitext(os.path.basename(src_file))[0]
      thumb_file = os.path.join(thumb_dir,
                                'sphx_glr_%s_thumb.%s' % (base_image_name, ext))
  
      if src_file in gallery_conf['failing_examples']:
          img = os.path.join(glr_path_static(), 'broken_example.png')
      elif os.path.exists(thumbnail_image_path):
          img = thumbnail_image_path
      elif not os.path.exists(thumb_file):
          # create something to replace the thumbnail
          img = os.path.join(glr_path_static(), 'no_image.png')
          img = gallery_conf.get("default_thumb_file", img)
      else:
          return
      if ext == 'svg':
          copyfile(img, thumb_file)
      else:
          scale_image(img, thumb_file, *gallery_conf["thumbnail_size"])
docs: Generate and Save the thumbnail image
  
      Parameters
      ----------
      image_path_template : str
          holds the template where to save and how to name the image
      src_file : str
          path to source python file
      gallery_conf : dict
          Sphinx-Gallery configuration dictionary