crac

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

统计

imgtobase64

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# -*- 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

 

 

---------------------2020-10-22---------------------

 

postdata = base64.b64decode(postdata)

将数据保存为文件即可

posted on   crac  阅读(476)  评论(0编辑  收藏  举报

点击右上角即可分享
微信分享提示