code: def _save(im, fp, filename):
      # Get the keyword arguments
      info = im.encoderinfo
  
      if filename.endswith(".j2k") or info.get("no_jp2", False):
          kind = "j2k"
      else:
          kind = "jp2"
  
      offset = info.get("offset", None)
      tile_offset = info.get("tile_offset", None)
      tile_size = info.get("tile_size", None)
      quality_mode = info.get("quality_mode", "rates")
      quality_layers = info.get("quality_layers", None)
      if quality_layers is not None and not (
          isinstance(quality_layers, (list, tuple))
          and all(
              [
                  isinstance(quality_layer, (int, float))
                  for quality_layer in quality_layers
              ]
          )
      ):
          msg = "quality_layers must be a sequence of numbers"
          raise ValueError(msg)
  
      num_resolutions = info.get("num_resolutions", 0)
      cblk_size = info.get("codeblock_size", None)
      precinct_size = info.get("precinct_size", None)
      irreversible = info.get("irreversible", False)
      progression = info.get("progression", "LRCP")
      cinema_mode = info.get("cinema_mode", "no")
      mct = info.get("mct", 0)
      signed = info.get("signed", False)
      comment = info.get("comment")
      if isinstance(comment, str):
          comment = comment.encode()
      plt = info.get("plt", False)
  
      fd = -1
      if hasattr(fp, "fileno"):
          try:
              fd = fp.fileno()
          except Exception:
              fd = -1
  
      im.encoderconfig = (
          offset,
          tile_offset,
          tile_size,
          quality_mode,
          quality_layers,
          num_resolutions,
          cblk_size,
          precinct_size,
          irreversible,
          progression,
          cinema_mode,
          mct,
          signed,
          fd,
          comment,
          plt,
      )
  
      ImageFile._save(im, fp, [("jpeg2k", (0, 0) + im.size, 0, kind)])
  
imports: import io
  import os
  import struct
  from .None import Image, ImageFile, _binary
label_desc: Use image node_id 5 for calling a global function with example usage: _save(im, fp, filename) without return types