Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(30)  |  Call(14)  |  Derive(0)  |  Import(16)
Return a list of strings representing a GIF header

        def getheader(im, palette=None, info=None):
    """Return a list of strings representing a GIF header"""

    optimize = info and info.get("optimize", 0)

    # Header Block
    # http://www.matthewflickinger.com/lab/whatsinagif/bits_and_bytes.asp
    header = [
        b"GIF87a" +             # signature + version
        o16(im.size[0]) +       # canvas width
        o16(im.size[1])         # canvas height
    ]

    if im.mode == "P":
        if palette and isinstance(palette, bytes):
            sourcePalette = palette[:768]
        else:
            sourcePalette = im.im.getpalette("RGB")[:768]
    else: # L-mode
        if palette and isinstance(palette, bytes):
            sourcePalette = palette[:768]
        else:
            sourcePalette = bytearray([i//3 for i in range(768)])

    usedPaletteColors = paletteBytes = None

    if optimize:
        usedPaletteColors = []

        # check which colors are used
        i = 0
        for count in im.histogram():
            if count:
                usedPaletteColors.append(i)
            i += 1

        # create the new palette if not every color is used
        if len(usedPaletteColors) < 256:
            paletteBytes = b""
            newPositions = {}

            i = 0
            # pick only the used colors from the palette
            for oldPosition in usedPaletteColors:
                paletteBytes += sourcePalette[oldPosition*3:oldPosition*3+3]
                newPositions[oldPosition] = i
                i += 1

            # replace the palette color id of all pixel with the new id
            imageBytes = bytearray(im.tobytes())
            for i in range(len(imageBytes)):
                imageBytes[i] = newPositions[imageBytes[i]]
            im.frombytes(bytes(imageBytes))

    if not paletteBytes:
        paletteBytes = sourcePalette

    # Logical Screen Descriptor
    # calculate the palette size for the header
    import math
    colorTableSize = int(math.ceil(math.log(len(paletteBytes)//3, 2)))-1
    if colorTableSize < 0: colorTableSize = 0
    # size of global color table + global color table flag
    header.append(o8(colorTableSize + 128))
    # background + reserved/aspect
    header.append(o8(0) + o8(0))
    # end of Logical Screen Descriptor

    # add the missing amount of bytes
    # the palette has to be 2< 0:
        paletteBytes += o8(0) * 3 * actualTargetSizeDiff

    # Header + Logical Screen Descriptor + Global Color Table
    header.append(paletteBytes)
    return header, usedPaletteColors
        


src/s/i/SimpleCV-HEAD/SimpleCV/examples/web-based/cloudanimator/images2gif.py   SimpleCV(Download)
    import PIL
    from PIL import Image, ImageChops
    from PIL.GifImagePlugin import getheader, getdata
except ImportError:
    PIL = None
 
            # gather data
            palette = getheader(im)[1]
            data = getdata(im)
            imdes, data = data[0], data[1:]

src/p/i/Pillow-2.4.0/Scripts/gifmaker.py   Pillow(Download)
from PIL import Image, ImageChops
 
from PIL.GifImagePlugin import getheader, getdata
 
# --------------------------------------------------------------------
 
            # global header
            for s in getheader(im) + getdata(im):
                fp.write(s)
 

src/p/i/Pillow-HEAD/Scripts/gifmaker.py   Pillow(Download)
from PIL import Image, ImageChops
 
from PIL.GifImagePlugin import getheader, getdata
 
# --------------------------------------------------------------------
 
            # global header
            for s in getheader(im) + getdata(im):
                fp.write(s)
 

src/c/x/CXPhasing-0.3.0/cxphasing/images2gif.py   CXPhasing(Download)
    import PIL
    from PIL import Image, ImageChops
    from PIL.GifImagePlugin import getheader, getdata
except ImportError:
    PIL = None
 
            # gather data
            palette = getheader(im)[1]
            data = getdata(im)
            imdes, data = data[0], data[1:]            

src/f/l/flightloggin2-HEAD/graphs/images2gif.py   flightloggin2(Download)
    import PIL
    from PIL import Image, ImageChops
    from PIL.GifImagePlugin import getheader, getdata
except ImportError:
    PIL = None
 
            # gather data
            palette = getheader(im)[1]
            data = getdata(im)
            imdes, data = data[0], data[1:]            

src/d/o/dotHiero-HEAD/Startup/images2gif.py   dotHiero(Download)
    import PIL
    from PIL import Image, ImageChops
    from PIL.GifImagePlugin import getheader, getdata
except ImportError:
    PIL = None
 
            # gather data
            palette = getheader(im)[1]
            data = getdata(im)
            imdes, data = data[0], data[1:]            

src/t/h/thumbor-4.1.3/thumbor/engines/extensions/pil.py   thumbor(Download)
    import PIL
    from PIL import Image
    from PIL.GifImagePlugin import getheader, getdata
except ImportError:
    PIL = None
        palettes, occur = [], []
        for im in images:
            header, usedPaletteColors = getheader(im)
            palettes.append(header[-1])  # Last part of the header is the frame palette
        for palette in palettes:

src/t/h/thumbor-HEAD/thumbor/engines/extensions/pil.py   thumbor(Download)
    import PIL
    from PIL import Image
    from PIL.GifImagePlugin import getheader, getdata
except ImportError:
    PIL = None
        palettes, occur = [], []
        for im in images:
            header, usedPaletteColors = getheader(im)
            palettes.append(header[-1])  # Last part of the header is the frame palette
        for palette in palettes:

src/a/p/appengine-mandelbrot-python-HEAD/mandelbrot_animation.py   appengine-mandelbrot-python(Download)
 
    # Palette
    stream.write(GifImagePlugin.getheader(image)[1])
 
    # Application Extension

src/d/j/django-cropduster-4.2.24/cropduster/utils/images2gif.py   django-cropduster(Download)
    import PIL
    from PIL import Image
    from PIL.GifImagePlugin import getheader, getdata
except ImportError:
    PIL = None
        palettes, occur = [], []
        for im in images:
            palettes.append(getheader(im)[0][-1])
        for palette in palettes:
            occur.append(palettes.count(palette))

  1 | 2  Next