code: def save_image(img, outpath, delete_after_write=False):
      """Save an image to file.
  
      We are using RGBA by default, but not all types can use RGBA, such as JPEG,
      so this handles conversions if needed.
  
      For output format validation purposes, saving a test image to disk verifies
      that the specified output format is supported by PIL, as there's no API to
      verify that the image format string is allowed other than by attempting to
      save the image.
  
      Args:
        img: PIL Image object.
        outpath: Full output path for image along with image format extension.
                 E.g., /path/to/myimage.jpg
        delete_after_write: If True, will delete the image after writing it. This
                            should be used when writing a test image to disk to
                            verify that PIL can actually output the specified image
                            format.
      """
      try:
          img.save(outpath)
      except IOError:
          logging.warn(
              "Unable to save image as RGBA to desired output format. "
              "Converting to RGB and retrying."
          )
          img.convert("RGB").save(outpath)
          logging.info("Successfully saved image in RGB color space.")
  
      if delete_after_write:
          os.remove(outpath)
  
file_path: facets/facets_atlasmaker/atlasmaker_io.py
imports: import io
  import json
  import os
  import time
  import sys
  from absl import logging
  from PIL import Image
  import requests
  from requests.exceptions import Timeout
label_desc: Use image node_id 6 for calling a global function with example usage: save_image(img, outpath, delete_after_write) without return types