コード例 #1
0
ファイル: images.py プロジェクト: tshirtman/WeasyPrint
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
ファイル: images.py プロジェクト: Edinunzio/WeasyPrint
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
ファイル: images.py プロジェクト: shaan360/WeasyPrint
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