code: def png_to_base64(image_file):
      # assert image_file.lower().endswith('jpg') or image_file.lower().endswith('jpeg')
      from PIL import Image
  
      EXTENSIONS = {
          ".png": "PNG",
          ".apng": "PNG",
          ".blp": "BLP",
          ".bmp": "BMP",
          ".dib": "DIB",
          ".bufr": "BUFR",
          ".cur": "CUR",
          ".pcx": "PCX",
          ".dcx": "DCX",
          ".dds": "DDS",
          ".ps": "EPS",
          ".eps": "EPS",
          ".fit": "FITS",
          ".fits": "FITS",
          ".fli": "FLI",
          ".flc": "FLI",
          ".fpx": "FPX",
          ".ftc": "FTEX",
          ".ftu": "FTEX",
          ".gbr": "GBR",
          ".gif": "GIF",
          ".grib": "GRIB",
          ".h5": "HDF5",
          ".hdf": "HDF5",
          ".jp2": "JPEG2000",
          ".j2k": "JPEG2000",
          ".jpc": "JPEG2000",
          ".jpf": "JPEG2000",
          ".jpx": "JPEG2000",
          ".j2c": "JPEG2000",
          ".icns": "ICNS",
          ".ico": "ICO",
          ".im": "IM",
          ".iim": "IPTC",
          ".jfif": "JPEG",
          ".jpe": "JPEG",
          ".jpg": "JPEG",
          ".jpeg": "JPEG",
          ".tif": "TIFF",
          ".tiff": "TIFF",
          ".mic": "MIC",
          ".mpg": "MPEG",
          ".mpeg": "MPEG",
          ".mpo": "MPO",
          ".msp": "MSP",
          ".palm": "PALM",
          ".pcd": "PCD",
          ".pdf": "PDF",
          ".pxr": "PIXAR",
          ".pbm": "PPM",
          ".pgm": "PPM",
          ".ppm": "PPM",
          ".pnm": "PPM",
          ".psd": "PSD",
          ".qoi": "QOI",
          ".bw": "SGI",
          ".rgb": "SGI",
          ".rgba": "SGI",
          ".sgi": "SGI",
          ".ras": "SUN",
          ".tga": "TGA",
          ".icb": "TGA",
          ".vda": "TGA",
          ".vst": "TGA",
          ".webp": "WEBP",
          ".wmf": "WMF",
          ".emf": "WMF",
          ".xbm": "XBM",
          ".xpm": "XPM",
      }
  
      from pathlib import Path
  
      ext = Path(image_file).suffix
      if ext in EXTENSIONS:
          iformat = EXTENSIONS[ext]
      else:
          raise ValueError(
              "Invalid file extension %s for file %s"
              % (ext, image_file)
          )
  
      image = Image.open(image_file)
      buffered = BytesIO()
      image.save(buffered, format=iformat)
      img_str = base64.b64encode(buffered.getvalue())
      # FIXME: unsure about below
      img_str = str(
          bytes(
              "data:image/%s;base64," % iformat.lower(),
              encoding="utf-8",
          )
          + img_str
      )
  
      return img_str
  
label_desc: Use image node_id 1 for calling a global function with example usage: png_to_base64(image_file) and returns: img_str