code: def overlay_image(
      image: Union[str, Image.Image],
      overlay: 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,
      max_visible_opacity: float = 0.75,
      metadata: Optional[List[Dict[str, Any]]] = None,
      bboxes: Optional[List[Tuple]] = None,
      bbox_format: Optional[str] = None,
  ) -> Image.Image:
      """
      Overlays an image onto another 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 overlay: the path to an image or a variable of type PIL.Image.Image
          that 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 original image
  
      @param x_pos: position of overlaid image relative to the image width
  
      @param max_visible_opacity: if bboxes are passed in, this param will be used as the
          maximum opacity value through which the src image will still be considered
          visible; see the function `overlay_image_bboxes_helper` in `utils/bboxes.py` for
          more details about how this is used. If bboxes are not passed in this is not used
  
      @param y_pos: position of overlaid image relative to the image height
  
      @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 <= opacity <= 1.0
      ), "Opacity must be a value in the range [0, 1]"
      assert (
          0.0 <= overlay_size <= 1.0
      ), "Image size must be a value in the range [0, 1]"
      assert (
          0.0 <= x_pos <= 1.0
      ), "x_pos must be a value in the range [0, 1]"
      assert (
          0.0 <= y_pos <= 1.0
      ), "y_pos 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
  
      overlay = imutils.validate_and_load_image(overlay)
  
      im_width, im_height = image.size
      overlay_width, overlay_height = overlay.size
      new_height = max(1, int(im_height * overlay_size))
      new_width = int(overlay_width * new_height / overlay_height)
      overlay = overlay.resize((new_width, new_height))
  
      try:
          mask = overlay.convert("RGBA").getchannel("A")
          mask = Image.fromarray(
              (np.array(mask) * opacity).astype(np.uint8)
          )
      except ValueError:
          mask = Image.new(
              mode="L", size=overlay.size, color=int(opacity * 255)
          )
  
      x = int(im_width * x_pos)
      y = int(im_height * y_pos)
  
      aug_image = image.convert(mode="RGBA")
      aug_image.paste(im=overlay, box=(x, y), mask=mask)
  
      imutils.get_metadata(
          metadata=metadata,
          function_name="overlay_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 18 for calling a global function with example usage: overlay_image(image, overlay, output_path, opacity, overlay_size, x_pos, y_pos, max_visible_opacity, metadata, bboxes, bbox_format) and returns: imutils