code: def save_image_with_geninfo(
      image,
      geninfo,
      filename,
      extension=None,
      existing_pnginfo=None,
      pnginfo_section_name="parameters",
  ):
      """
      Saves image to filename, including geninfo as text information for generation info.
      For PNG images, geninfo is added to existing pnginfo dictionary using the pnginfo_section_name argument as key.
      For JPG images, there's no dictionary and geninfo just replaces the EXIF description.
      """
  
      if extension is None:
          extension = os.path.splitext(filename)[1]
  
      image_format = Image.registered_extensions()[extension]
  
      if extension.lower() == ".png":
          existing_pnginfo = existing_pnginfo or {}
          if opts.enable_pnginfo:
              existing_pnginfo[pnginfo_section_name] = geninfo
  
          if opts.enable_pnginfo:
              pnginfo_data = PngImagePlugin.PngInfo()
              for k, v in (existing_pnginfo or {}).items():
                  pnginfo_data.add_text(k, str(v))
          else:
              pnginfo_data = None
  
          image.save(
              filename,
              format=image_format,
              quality=opts.jpeg_quality,
              pnginfo=pnginfo_data,
          )
  
      elif extension.lower() in (".jpg", ".jpeg", ".webp"):
          if image.mode == "RGBA":
              image = image.convert("RGB")
          elif image.mode == "I;16":
              image = image.point(
                  lambda p: p * 0.0038910505836576
              ).convert("RGB" if extension.lower() == ".webp" else "L")
  
          image.save(
              filename,
              format=image_format,
              quality=opts.jpeg_quality,
              lossless=opts.webp_lossless,
          )
  
          if opts.enable_pnginfo and geninfo is not None:
              exif_bytes = piexif.dump(
                  {
                      "Exif": {
                          piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(
                              geninfo or "", encoding="unicode"
                          )
                      },
                  }
              )
  
              piexif.insert(exif_bytes, filename)
      elif extension.lower() == ".gif":
          image.save(filename, format=image_format, comment=geninfo)
      else:
          image.save(
              filename, format=image_format, quality=opts.jpeg_quality
          )
  
imports: from __future__ import annotations
  import datetime
  import pytz
  import io
  import math
  import os
  from collections import namedtuple
  import re
  import numpy
  import piexif
  import piexif.helper
  from PIL import Image, ImageFont, ImageDraw, ImageColor, PngImagePlugin
  import string
  import json
  import hashlib
  from modules import sd_samplers, shared, script_callbacks, errors
  from modules.paths_internal import roboto_ttf_file
  from modules.shared import opts
label_desc: Use image node_id 10 for calling a global function with example usage: save_image_with_geninfo(image, geninfo, filename, extension, existing_pnginfo, pnginfo_section_name) without return types