code: def create_thumbnail(
      infile,
      thumbfile,
      scale=0.2,
      max_width=200,
      max_height=150,
      interpolation="bilinear",
  ):
      """
      Create a thumbnail of an image
      """
      basedir, basename = os.path.split(infile)
      baseout, extout = os.path.splitext(thumbfile)
  
      im = image.imread(infile)
      rows, cols, depth = im.shape
  
      # this doesn't really matter, it will cancel in the end, but we
      # need it for the mpl API
      dpi = 100
  
      scale = min(scale, max_height / float(rows))
      scale = min(scale, max_width / float(cols))
  
      height = float(rows) / dpi * scale
      width = float(cols) / dpi * scale
  
      extension = extout.lower()
  
      if extension == ".png":
          from matplotlib.backends.backend_agg import (
              FigureCanvasAgg as FigureCanvas,
          )
      elif extension == ".pdf":
          from matplotlib.backends.backend_pdf import (
              FigureCanvasPDF as FigureCanvas,
          )
      elif extension == ".svg":
          from matplotlib.backends.backend_svg import (
              FigureCanvasSVG as FigureCanvas,
          )
      else:
          raise ValueError(
              "Can only handle extensions 'png', 'svg' or 'pdf'"
          )
  
      from matplotlib.figure import Figure
  
      fig = Figure(figsize=(width, height), dpi=dpi)
      canvas = FigureCanvas(fig)
  
      ax = fig.add_axes(
          [0, 0, 1, 1],
          aspect="auto",
          frameon=False,
          xticks=[],
          yticks=[],
      )
  
      basename, ext = os.path.splitext(basename)
      ax.imshow(
          im, aspect="auto", resample=True, interpolation="bilinear"
      )
      fig.savefig(thumbfile, dpi=dpi)
      return fig
  
imports: import sys
  import os
  import traceback
  import token
  import tokenize
  import gc
  import shutil
  import glob
  import warnings
  import matplotlib
  from matplotlib import image
  from matplotlib import pyplot
label_desc: Use image node_id 1 for calling a global function with example usage: create_thumbnail(infile, thumbfile, scale, max_width, max_height, interpolation) and returns: fig