python获得图片base64编码示例

yipeiwu_com6年前Python基础

 

复制代码 代码如下:

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

PS:这里再为大家推荐几款在线图片工具供大家参考使用

图片转换为Base64编码在线工具:
http://tools.jb51.net/transcoding/img2base64

在线Email邮箱图标制作工具:
http://tools.jb51.net/email/emaillogo

在线PS图像处理工具:
http://tools.jb51.net/aideddesign/webps

在线图片格式转换(jpg/bmp/gif/png)工具:
http://tools.jb51.net/aideddesign/picext

ICO图标在线生成工具:
http://tools.jb51.net/aideddesign/ico_img

相关文章

Python里隐藏的“禅”

在 python的lib目录里有一个:this.py,它其实是隐藏着一首诗,源码如下:复制代码 代码如下:s = """Gur Mra bs Clguba, ol Gvz Crgref...

对python修改xml文件的节点值方法详解

这是我的xml文件结构 <?xml version='1.0' encoding='utf-8'?> <annotation> <fo...

python 单线程和异步协程工作方式解析

在python3.4之后新增了asyncio模块,可以帮我们检测IO(只能是网络IO【HTTP连接就是网络IO操作】),实现应用程序级别的切换(异步IO)。注意:asyncio只能发tc...

Python3获取电脑IP、主机名、Mac地址的方法示例

本文实例讲述了Python3获取电脑IP、主机名、Mac地址的方法。分享给大家供大家参考,具体如下: # -*- coding:utf-8 -*- #! python3 ''' Cr...

使用python生成杨辉三角形的示例代码

使用python生成杨辉三角形的示例代码

杨辉三角杨辉 定义如下: 1 / \ 1 1 / \ / \ 1 2 1 / \ / \ / \ 1 3 3 1 / \...