code: def _save(im, fp, filename):
      if im.mode == "1":
          rawmode, head = "1;I", b"P4"
      elif im.mode == "L":
          rawmode, head = "L", b"P5"
      elif im.mode == "I":
          rawmode, head = "I;16B", b"P5"
      elif im.mode in ("RGB", "RGBA"):
          rawmode, head = "RGB", b"P6"
      else:
          msg = f"cannot write mode {im.mode} as PPM"
          raise OSError(msg)
      fp.write(head + b"\n%d %d\n" % im.size)
      if head == b"P6":
          fp.write(b"255\n")
      elif head == b"P5":
          if rawmode == "L":
              fp.write(b"255\n")
          else:
              fp.write(b"65535\n")
      ImageFile._save(
          im, fp, [("raw", (0, 0) + im.size, 0, (rawmode, 0, 1))]
      )
  
imports: from .None import Image, ImageFile
  from ._binary import i16be
  from ._binary import o8
  from ._binary import o32le
label_desc: Use image node_id 2 for calling a global function with example usage: _save(im, fp, filename) without return types