def _save(im, fp, filename):

    if _imaging_gif:
        # call external driver
        try:
            _imaging_gif.save(im, fp, filename)
            return
        except IOError:
            pass # write uncompressed file

    try:
        rawmode = RAWMODE[im.mode]
        imOut = im
    except KeyError:
        # convert on the fly (EXPERIMENTAL -- I'm not sure PIL
        # should automatically convert images on save...)
        if Image.getmodebase(im.mode) == "RGB":
            imOut = im.convert("P")
            rawmode = "P"
        else:
            imOut = im.convert("L")
            rawmode = "L"

    # header
    for s in getheader(imOut, im.encoderinfo):
        fp.write(s)

    flags = 0

    try:
        interlace = im.encoderinfo["interlace"]
    except KeyError:
        interlace = 1

    # workaround for @PIL153
    if min(im.size) < 16:
        interlace = 0

    if interlace:
        flags = flags | 64

    try:
        transparency = im.encoderinfo["transparency"]
    except KeyError:
        pass
    else:
        # transparency extension block
        fp.write("!" +
                 chr(249) +             # extension intro
                 chr(4) +               # length
                 chr(1) +               # transparency info present
                 o16(0) +               # duration
                 chr(int(transparency)) # transparency index
                 + chr(0))

    # local image header
    fp.write("," +
             o16(0) + o16(0) +          # bounding box
             o16(im.size[0]) +          # size
             o16(im.size[1]) +
             chr(flags) +               # flags
             chr(8))                    # bits

    imOut.encoderconfig = (8, interlace)

    ImageFile._save(imOut, fp, [("gif", (0,0)+im.size, 0, rawmode)])

    fp.write("\0") # end of image data

    fp.write(";") # end of file

    try:
        fp.flush()
    except: pass
dataset/ETHPy150Open kleientertainment/ds_mod_tools/pkg/win32/Python27/Lib/site-packages/PIL/GifImagePlugin.py/_save/original