code: def _save(im: Image.Image, fp: BytesIO, filename: str) -> None:
      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"
      elif im.mode == "F":
          rawmode, head = "F;32F", b"Pf"
      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")
      elif head == b"Pf":
          fp.write(b"-1.0\n")
      row_order = -1 if im.mode == "F" else 1
      ImageFile._save(
          im,
          fp,
          [("raw", (0, 0) + im.size, 0, (rawmode, 0, row_order))],
      )
  
imports: from __future__ import annotations
  import math
  from io import BytesIO
  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