用Python 获取图片的Base64编码

admin 2014年5月13日14:53:24Python评论2,066 次浏览阅读模式

用Python 获取图片的Base64编码,源代码如下:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
# base64-pic.py
'''

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) < LIMIT:
                break
print os.linesep.join(liIcon)

 

相关文章
weinxin
我的微信
微信扫一扫
admin
  • 本文由 发表于 2014年5月13日14:53:24
  • 转载请务必保留本文链接:https://anyun.org/a/jishuguanzhu/bianchengchalou/python/2014/0513/1079.html

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: