'Write the VideoClip to a GIF file.
Converts a VideoClip into an animated GIF using ImageMagick
or ffmpeg.
Parameters
filename
Name of the resulting gif file.
fps
Number of frames per second (see note below). If it
isn\'t provided, then the function will look for the clip\'s
``fps`` attribute (VideoFileClip, for instance, have one).
program
Software to use for the conversion, either \'imageio\' (this will use
the library FreeImage through ImageIO), or \'ImageMagick\', or \'ffmpeg\'.
opt
Optimalization to apply. If program=\'imageio\', opt must be either \'wu\'
(Wu) or \'nq\' (Neuquant). If program=\'ImageMagick\',
either \'optimizeplus\' or \'OptimizeTransparency\'.
fuzz
(ImageMagick only) Compresses the GIF by considering that
the colors that are less than fuzz% different are in fact
the same.
Notes
The gif will be playing the clip in real time (you can
only change the frame rate). If you want the gif to be played
slower than the clip you will use ::
>>> # slow down clip 50% and make it a gif
>>> myClip.speedx(0.5).to_gif(\'myClip.gif\')'

@requires_duration
@convert_masks_to_RGB
def write_gif(self, filename, fps=None, program='imageio', opt='nq', fuzz=1, verbose=True, loop=0, dispose=False, colors=None, tempfiles=False):

    if (program == 'imageio'):
        write_gif_with_image_io(self, filename, fps=fps, opt=opt, loop=loop, verbose=verbose, colors=colors)
    elif tempfiles:
        opt1 = opt
        if (opt1 == 'nq'):
            opt1 = 'optimizeplus'
        else:
            opt1 = 'OptimizeTransparency'
        write_gif_with_tempfiles(self, filename, fps=fps, program=program, opt=opt1, fuzz=fuzz, verbose=verbose, loop=loop, dispose=dispose, colors=colors)
    else:
        write_gif(self, filename, fps=fps, program=program, opt=opt, fuzz=fuzz, verbose=verbose, loop=loop, dispose=dispose, colors=colors)
