code: def overlay_onto_background_image(
      image: Union[str, Image.Image],
      background_image: Union[str, Image.Image],
      output_path: Optional[str] = None,
      opacity: float = 1.0,
      overlay_size: float = 1.0,
      x_pos: float = 0.4,
      y_pos: float = 0.4,
      scale_bg: bool = False,
      metadata: Optional[List[Dict[str, Any]]] = None,
      bboxes: Optional[List[Tuple]] = None,
      bbox_format: Optional[str] = None,
  ) -> Image.Image:
      """
      Overlays the image onto a given background image at position
      (width * x_pos, height * y_pos)
  
      @param image: the path to an image or a variable of type PIL.Image.Image
          to be augmented
  
      @param background_image: the path to an image or a variable of type PIL.Image.Image
          onto which the source image will be overlaid
  
      @param output_path: the path in which the resulting image will be stored.
          If None, the resulting PIL Image will still be returned
  
      @param opacity: the lower the opacity, the more transparent the overlaid image
  
      @param overlay_size: size of the overlaid image is overlay_size * height
          of the background image
  
      @param x_pos: position of overlaid image relative to the background image width with
          respect to the x-axis
  
      @param y_pos: position of overlaid image relative to the background image height with
          respect to the y-axis
  
      @param scale_bg: if True, the background image will be scaled up or down so that
          overlay_size is respected; if False, the source image will be scaled instead
  
      @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
      """
      assert (
          0.0 <= overlay_size <= 1.0
      ), "Image size must be a value in the range [0, 1]"
  
      image = imutils.validate_and_load_image(image)
  
      func_kwargs = imutils.get_func_kwargs(metadata, locals())
      src_mode = image.mode
  
      if scale_bg:
          background_image = resize(
              background_image,
              width=math.floor(image.width / overlay_size),
              height=math.floor(image.height / overlay_size),
          )
  
      aug_image = overlay_image(
          background_image,
          overlay=image,
          output_path=output_path,
          opacity=opacity,
          overlay_size=overlay_size,
          x_pos=x_pos,
          y_pos=y_pos,
      )
  
      imutils.get_metadata(
          metadata=metadata,
          function_name="overlay_onto_background_image",
          aug_image=aug_image,
          **func_kwargs,
      )
  
      return imutils.ret_and_save_image(
          aug_image, 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 19 for calling a global function with example usage: overlay_onto_background_image(image, background_image, output_path, opacity, overlay_size, x_pos, y_pos, scale_bg, metadata, bboxes, bbox_format) and returns: imutils