code: def _save(im, fp, filename):
      """
      Saves the image as a series of PNG files,
      that are then converted to a .icns file
      using the macOS command line utility 'iconutil'.
  
      macOS only.
      """
      if hasattr(fp, "flush"):
          fp.flush()
  
      # create the temporary set of pngs
      iconset = tempfile.mkdtemp(".iconset")
      provided_images = {
          im.width: im for im in im.encoderinfo.get("append_images", [])
      }
      last_w = None
      second_path = None
      for w in [16, 32, 128, 256, 512]:
          prefix = "icon_{}x{}".format(w, w)
  
          first_path = os.path.join(iconset, prefix + ".png")
          if last_w == w:
              shutil.copyfile(second_path, first_path)
          else:
              im_w = provided_images.get(
                  w, im.resize((w, w), Image.LANCZOS)
              )
              im_w.save(first_path)
  
          second_path = os.path.join(iconset, prefix + "@2x.png")
          im_w2 = provided_images.get(
              w * 2, im.resize((w * 2, w * 2), Image.LANCZOS)
          )
          im_w2.save(second_path)
          last_w = w * 2
  
      # iconutil -c icns -o {} {}
      from subprocess import Popen, PIPE, CalledProcessError
  
      convert_cmd = ["iconutil", "-c", "icns", "-o", filename, iconset]
      with open(os.devnull, "wb") as devnull:
          convert_proc = Popen(convert_cmd, stdout=PIPE, stderr=devnull)
  
      convert_proc.stdout.close()
  
      retcode = convert_proc.wait()
  
      # remove the temporary files
      shutil.rmtree(iconset)
  
      if retcode:
          raise CalledProcessError(retcode, convert_cmd)
  
imports: import io
  import os
  import shutil
  import struct
  import sys
  import tempfile
  from PIL import Image, ImageFile, PngImagePlugin
  from PIL._binary import i8
label_desc: Use image node_id 6 for calling a global function with example usage: _save(im, fp, filename) without return types