code: def _encode_tile(im, fp, tile: list[_Tile], bufsize, fh, exc=None):
      for encoder_name, extents, offset, args in tile:
          if offset > 0:
              fp.seek(offset)
          encoder = Image._getencoder(
              im.mode, encoder_name, args, im.encoderconfig
          )
          try:
              encoder.setimage(im.im, extents)
              if encoder.pushes_fd:
                  encoder.setfd(fp)
                  errcode = encoder.encode_to_pyfd()[1]
              else:
                  if exc:
                      # compress to Python file-compatible object
                      while True:
                          errcode, data = encoder.encode(bufsize)[1:]
                          fp.write(data)
                          if errcode:
                              break
                  else:
                      # slight speedup: compress to real file object
                      errcode = encoder.encode_to_file(fh, bufsize)
              if errcode < 0:
                  raise _get_oserror(errcode, encoder=True) from exc
          finally:
              encoder.cleanup()
  
imports: from __future__ import annotations
  import io
  import itertools
  import struct
  import sys
  from typing import Any, NamedTuple
  from .None import Image
  from ._deprecate import deprecate
  from ._util import is_path
label_desc: Use image node_id 5 for calling a global function with example usage: _encode_tile(im, fp, tile, bufsize, fh, exc) without return types