code: def write_gif_with_tempfiles(
      clip,
      filename,
      fps=None,
      program="ImageMagick",
      opt="OptimizeTransparency",
      fuzz=1,
      loop=0,
      dispose=True,
      colors=None,
      pixel_format=None,
      logger="bar",
  ):
      """Write the VideoClip to a GIF file.
  
  
      Converts a VideoClip into an animated GIF using ImageMagick
      or ffmpeg. Does the same as write_gif (see this one for more
      docstring), but writes every frame to a file instead of passing
      them in the RAM. Useful on computers with little RAM.
  
      Parameters
      ----------
  
      clip : moviepy.video.VideoClip.VideoClip
        The clip from which the frames will be extracted to create the GIF image.
  
      filename : str
        Name of the resulting gif file.
  
      fps : int, optional
        Number of frames per second. If it isn't provided, then the function will
        look for the clip's ``fps`` attribute.
  
      program : str, optional
        Software to use for the conversion, either ``"ImageMagick"`` or
        ``"ffmpeg"``.
  
      opt : str, optional
        ImageMagick only optimalization to apply, either ``"optimizeplus"`` or
        ``"OptimizeTransparency"``. Doesn't takes effect if ``program="ffmpeg"``.
  
      fuzz : float, optional
        ImageMagick only compression option which compresses the GIF by
        considering that the colors that are less than ``fuzz`` different are in
        fact the same.
  
      loop : int, optional
        Repeat the clip using ``loop`` iterations in the resulting GIF.
  
      dispose : bool, optional
        ImageMagick only option which, when enabled, the ImageMagick binary will
        take the argument `-dispose 2`, clearing the frame area with the
        background color, otherwise it will be defined as ``-dispose 1`` which
        will not dispose, just overlays next frame image.
  
      colors : int, optional
        ImageMagick only option for color reduction. Defines the maximum number
        of colors that the output image will have.
  
      pixel_format : str, optional
        FFmpeg pixel format for the output gif file. If is not specified
        ``"rgb24"`` will be used as the default format unless ``clip.mask``
        exist, then ``"rgba"`` will be used. Doesn't takes effect if
        ``program="ImageMagick"``.
  
      logger : str, optional
        Either ``"bar"`` for progress bar or ``None`` or any Proglog logger.
      """
      logger = proglog.default_bar_logger(logger)
      file_root, ext = os.path.splitext(filename)
      tt = np.arange(0, clip.duration, 1.0 / fps)
  
      tempfiles = []
  
      logger(message="MoviePy - Building file %s\n" % filename)
      logger(message="MoviePy - - Generating GIF frames")
  
      for i, t in logger.iter_bar(t=list(enumerate(tt))):
          name = "%s_GIFTEMP%04d.png" % (file_root, i + 1)
          tempfiles.append(name)
          clip.save_frame(name, t, with_mask=True)
  
      delay = int(100.0 / fps)
  
      if clip.mask is None:
          with_mask = False
  
      if program == "ImageMagick":
          if not pixel_format:
              pixel_format = "RGBA" if with_mask else "RGB"
  
          logger(
              message="MoviePy - - Optimizing GIF with ImageMagick..."
          )
          cmd = (
              [
                  IMAGEMAGICK_BINARY,
                  "-delay",
                  "%d" % delay,
                  "-dispose",
                  "%d" % (2 if dispose else 1),
                  "-loop",
                  "%d" % loop,
                  "%s_GIFTEMP*.png" % file_root,
                  "-coalesce",
                  "-fuzz",
                  "%02d" % fuzz + "%",
                  "-layers",
                  "%s" % opt,
                  "-set",
                  "colorspace",
                  pixel_format,
              ]
              + (
                  ["-colors", "%d" % colors]
                  if colors is not None
                  else []
              )
              + [filename]
          )
  
      elif program == "ffmpeg":
          if loop:
              clip = loop_fx(clip, n=loop)
  
          if not pixel_format:
              pixel_format = "rgba" if with_mask else "rgb24"
  
          cmd = [
              FFMPEG_BINARY,
              "-y",
              "-f",
              "image2",
              "-r",
              str(fps),
              "-i",
              file_root + "_GIFTEMP%04d.png",
              "-r",
              str(fps),
              filename,
              "-pix_fmt",
              (pixel_format),
          ]
  
      try:
          subprocess_call(cmd, logger=logger)
          logger(message="MoviePy - GIF ready: %s." % filename)
  
      except (IOError, OSError) as err:
          error = (
              "MoviePy Error: creation of %s failed because "
              "of the following error:\n\n%s.\n\n."
              % (filename, str(err))
          )
  
          if program == "ImageMagick":
              error += (
                  "This error can be due to the fact that "
                  "ImageMagick is not installed on your computer, or "
                  "(for Windows users) that you didn't specify the "
                  "path to the ImageMagick binary. Check the documentation."
              )
  
          raise IOError(error)
  
      for file in tempfiles:
          os.remove(file)
  
file_path: moviepy/moviepy/video/io/gif_writers.py
imports: import os
  import subprocess
  import numpy
  import proglog
  from moviepy.config import FFMPEG_BINARY, IMAGEMAGICK_BINARY
  from moviepy.decorators import requires_duration, use_clip_fps_by_default
  from moviepy.tools import cross_platform_popen_params, subprocess_call
  from moviepy.video.fx.loop import loop
label_desc: Use image node_id 1 for calling a global function with example usage: write_gif_with_tempfiles(clip, filename, fps, program, opt, fuzz, loop, dispose, colors, pixel_format, logger) without return types