예제 #1
0
def get_pixbuf(file_obj=None, string=None, chunck_size=16 * 1024):
    """Create a Pixbuf object."""
    loader = PixbufLoader()
    try:
        if file_obj:
            while 1:
                chunck = file_obj.read(chunck_size)
                if not chunck:
                    break
                loader.write(chunck)
        elif string:
            loader.write(string)
        else:
            raise ValueError('Could not load image: empty content')
    finally:
        # Pixbuf is really unhappy if we don’t do this:
        loader.close()
    return loader.get_pixbuf()
예제 #2
0
def get_pixbuf(file_obj=None, string=None, chunck_size=16 * 1024):
    """Create a Pixbuf object."""
    loader = PixbufLoader()
    if file_obj:
        while 1:
            chunck = file_obj.read(chunck_size)
            if not chunck:
                break
            loader.write(chunck)
    elif string:
        loader.write(string)
    else:
        raise ValueError('Could not load image: empty content')
    loader.close()
    return loader.get_pixbuf()
예제 #3
0
def get_pixbuf(file_obj=None, string=None, chunck_size=16 * 1024):
    """Create a Pixbuf object."""
    if file_obj:
        string = file_obj.read()
    if not string:
        raise ValueError('Could not load image: empty content')
    loader = PixbufLoader()
    try:
        loader.write(string)
    finally:
        # Pixbuf is really unhappy if we don’t do this:
        loader.close()
    jpeg_data = string if pixbuf_format(loader) == 'jpeg' else None
    return loader.get_pixbuf(), jpeg_data