Home >Backend Development >Python Tutorial >python获得图片base64编码示例

python获得图片base64编码示例

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-16 08:45:391325browse

 

复制代码 代码如下:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os, base64

icon = open('ya.png','rb')
iconData = icon.read()
iconData = base64.b64encode(iconData)
LIMIT = 60
liIcon = []
while True:
        sLimit = iconData[:LIMIT]
        iconData = iconData[LIMIT:]
        liIcon.append('\'%s\'' %sLimit)
        if len(sLimit)                 break
print os.linesep.join(liIcon)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn