base64图片内容下载转为图片保存

网页中的base64图片内容下载后,利用PIL转为图片保存
from skimage.io import imread
from PIL import Image
from cStringIO import StringIO
import matplotlib.pyplot as plt
import base64

"""
__author__: jkmiao
__date__: 2017-07-27 
__description__: base64图片内容下载转为图片保存
__example__:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHkAAAANCAYAAACNScGeAAAC+klEQVR42u1YQWRdQRQdX0REhKqI
6CJ0GVGfiqqKKl8WX1WUL4uKqhDVRVWEqqqKKF10Vd18XUR83X1VFRGqqouqUFXVbRf1fVUlKiIq
wusdznDdzry5L//Npno58t4/d+67886dmftijN/GCE8JUwX5acIzwkvCfcKACdtRY6TmYz6TyJtj
sQDvbJjwhHA68H5mCW3Cc8KS4Gw+d8FZLBP6PDHmEcNrTUJGmCvAzxAOCHcQvJP3gCPGSM1rfBqE
vRwRY/w44R5hB/Oved6N9f9FuIkcviKOM1uAG4Qr8PkOsbmtEbrg/7IqBu0HRA7xXwir7P48JjFR
YozUvMbnKmEzp3hjvF292yimkMifhDh2tzskVHB/SvhfRqwBVmi2SE74ErBBPqN6dj0ih/hxPKQq
/H8TrpUUIzWvncdyZIeK8U6IoRyR3xFuiEWxz0SWVkOsIdy/JTwIJWCJV7j2iRziL+EhMon32JbL
iJGa186jCRHmkfuo5xjK441C5As4Juz4i1jZSzmFswJ/t4jsqq9j21+XgXfYEpci5/FzOMekbYiz
pJcYqXntPG6xhqeLVd5gvjFeI/IoCuUAK7jr2aL5+Z2hGNzYDIWxxovDblM/UcnGI0CMb6B6pG2y
l9NrjNS8dh7y6FnHPCoF+ZDIFQjUZB3zolgcbnwLv9fZ7+cQd1Um84HwQ3SEtopeEx4r+Lo4+J11
WCX1GiM1b5Q+0iYxZqogHxK5hkKTOXwk3Mb1CO7f4FPUF7cuE3mIro/DCrBFeKTgB5HYrNhy7MPO
Kp8Ri5GaN0qfUNMzUpAPiewKrd8j8gquX0SaO7uYFozCdnO+k318C13zcWw5LXwqmBJjpOY1PjNs
lZ3Ey98qwMdE7sMZ3GRCX0fxTaAQM3Tx0wJjrBH7hiOyVJGPYfs4RLOxHfpO6yFGal7j0wa3h79t
FISW1zReVZzLLocOvoXdf+OyABZEL+DGl27DeFEpY6TmYz5WoDOeLVXLa20wUCBa68/5hPtv/5L9
AWGnpG3UmO4EAAAAAElFTkSuQmCC


"""

def transform_log(fname='/home/jkmiao/Downloads/2308_fenzhi_uniscid_all.log'):
    s = ''
    cnt = 1
    with open(fname) as fr:
        for line in fr:
            if line.strip():
                s += line
        #   print line
            if len(line)<5 and len(s)>50:
                s = s.replace('data:image/png;base64,', '')
                img = StringIO(base64.b64decode(s))
                img = Image.open(img)
                img.save('img/origin/%s.png' % cnt)
# plt.imshow(img) s
= '' cnt += 1

 

posted on 2017-07-27 11:38  星空守望者--jkmiao  阅读(857)  评论(0编辑  收藏  举报