code: def _encode_tile(im, fp, tile, bufsize, fh, exc=None):
      for e, b, o, a in tile:
          if o > 0:
              fp.seek(o)
          encoder = Image._getencoder(im.mode, e, a, im.encoderconfig)
          try:
              encoder.setimage(im.im, b)
              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:
                  msg = (
                      f"encoder error {errcode} when writing image file"
                  )
                  raise OSError(msg) from exc
          finally:
              encoder.cleanup()
  
imports: import io
  import itertools
  import struct
  import sys
  from .None import Image
  from ._util import is_path
label_desc: Use image node_id 4 for calling a global function with example usage: _encode_tile(im, fp, tile, bufsize, fh, exc) without return types