code: def overlay_onto_screenshot(
      image: Union[str, Image.Image],
      output_path: Optional[str] = None,
      template_filepath: str = utils.TEMPLATE_PATH,
      template_bboxes_filepath: str = utils.BBOXES_PATH,
      max_image_size_pixels: Optional[int] = None,
      crop_src_to_fit: bool = False,
      resize_src_to_match_template: bool = True,
      metadata: Optional[List[Dict[str, Any]]] = None,
      bboxes: Optional[List[Tuple]] = None,
      bbox_format: Optional[str] = None,
  ) -> Image.Image:
      """
      Overlay the image onto a screenshot template so it looks like it was
      screenshotted on Instagram
  
      @param image: the path to an image or a variable of type PIL.Image.Image
          to be augmented
  
      @param output_path: the path in which the resulting image will be stored.
          If None, the resulting PIL Image will still be returned
  
      @param template_filepath: iopath uri to the screenshot template
  
      @param template_bboxes_filepath: iopath uri to the file containing the
          bounding box for each template
  
      @param max_image_size_pixels: if provided, the template image and/or src image
          will be scaled down to avoid an output image with an area greater than this
          size (in pixels)
  
      @param crop_src_to_fit: if True, the src image will be cropped if necessary to fit
          into the template image if the aspect ratios are different. If False, the src
          image will instead be resized if needed
  
      @param resize_src_to_match_template: if True, the src image will be resized if it is
          too big or small in both dimensions to better match the template image. If False,
          the template image will be resized to match the src image instead. It can be
          useful to set this to True if the src image is very large so that the augmented
          image isn't huge, but instead is the same size as the template image
  
      @param metadata: if set to be a list, metadata about the function execution
          including its name, the source & dest width, height, etc. will be appended
          to the inputted list. If set to None, no metadata will be appended or returned
  
      @param bboxes: a list of bounding boxes can be passed in here if desired. If
          provided, this list will be modified in place such that each bounding box is
          transformed according to this function
  
      @param bbox_format: signifies what bounding box format was used in `bboxes`. Must
          specify `bbox_format` if `bboxes` is provided. Supported bbox_format values are
          "pascal_voc", "pascal_voc_norm", "coco", and "yolo"
  
      @returns: the augmented PIL Image
      """
      image = imutils.validate_and_load_image(image)
  
      func_kwargs = imutils.get_func_kwargs(metadata, locals())
      src_mode = image.mode
  
      template, bbox = imutils.get_template_and_bbox(
          template_filepath, template_bboxes_filepath
      )
  
      if resize_src_to_match_template:
          bbox_w, bbox_h = bbox[2] - bbox[0], bbox[3] - bbox[1]
          image = scale(
              image,
              factor=min(bbox_w / image.width, bbox_h / image.height),
          )
      else:
          template, bbox = imutils.scale_template_image(
              image.size[0],
              image.size[1],
              template,
              bbox,
              max_image_size_pixels,
              crop_src_to_fit,
          )
          bbox_w, bbox_h = bbox[2] - bbox[0], bbox[3] - bbox[1]
  
      cropped_src = imutils.resize_and_pad_to_given_size(
          image, bbox_w, bbox_h, crop=crop_src_to_fit
      )
      template.paste(cropped_src, box=bbox)
  
      imutils.get_metadata(
          metadata=metadata,
          function_name="overlay_onto_screenshot",
          aug_image=template,
          **func_kwargs,
      )
  
      return imutils.ret_and_save_image(template, output_path, src_mode)
  
imports: import io
  import math
  import os
  import pickle
  from copy import deepcopy
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  import numpy
  from augly import utils
  from augly.image import utils
  from augly.image.utils.bboxes import spatial_bbox_helper
  from PIL import Image, ImageDraw, ImageEnhance, ImageFilter, ImageFont
label_desc: Use image node_id 20 for calling a global function with example usage: overlay_onto_screenshot(image, output_path, template_filepath, template_bboxes_filepath, max_image_size_pixels, crop_src_to_fit, resize_src_to_match_template, metadata, bboxes, bbox_format) and returns: imutils