码迷,mamicode.com
首页 > 其他好文 > 详细

imgtobase64

时间:2018-09-25 14:42:27      阅读:336      评论:0      收藏:0      [点我收藏+]

标签:save   code   bsp   odi   str   cst   highlight   binary   turn   

 

 

# -*- coding: utf-8 -*-

import re
import base64
from cStringIO import StringIO

from PIL import Image


def base64_to_image(base64_str, image_path=None):
    base64_data = re.sub(‘^data:image/.+;base64,‘, ‘‘, base64_str)
    binary_data = base64.b64decode(base64_data)
    img_data = StringIO(binary_data)
    img = Image.open(img_data)
    if image_path:
        img.save(image_path)
    return img

 from:

https://www.jianshu.com/p/2ff8e6f98257

imgtobase64

标签:save   code   bsp   odi   str   cst   highlight   binary   turn   

原文地址:https://www.cnblogs.com/crac/p/9699259.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!