utils.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:dbs-back 作者: Beit-Hatfutsot 项目源码 文件源码
def binarize_image(image):
    from PIL import Image

    binary = None

    try:
        im = Image.open(image)
        thumb = im.copy()
        thumb.thumbnail((260, 260))
        image_buffer = StringIO()
        thumb.save(image_buffer, "JPEG")
        binary = Binary(image_buffer.getvalue(), BINARY_SUBTYPE)
    except IOError as e:
        logging.error("failed to binarize image: "+str(e))
        return None

    # if image is a file object, rewind it
    finally:
        try:
            image.seek(0)
        except AttributeError:
            pass

    return binary
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号