Пример #1
0
def jpg_data(rgb, quality=85, optimize=True):
    # http://mail.python.org/pipermail/image-sig/1999-August/000816.html
    import ImageFile
    ImageFile.MAXBLOCK = 1000000  # default is 64k
    im = Image_from_array(rgb)
    tmp = tempfile.NamedTemporaryFile(suffix='.jpg')
    name = tmp.name
    # TODO: try / redo
    try:
        im.save(name, quality=quality, optimize=optimize)
    except Exception as e:
        logger.error('Could not convert: %s' % e)
        im.save(name)
        
    return open(name, 'rb').read()
Пример #2
0
def png_data(rgb):
    im = Image_from_array(rgb)
    tmp = tempfile.NamedTemporaryFile(suffix='.png')
    name = tmp.name
    im.save(name)
    return open(name, 'rb').read()