python获得图片base64编码示例

yipeiwu_com5年前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多继承以及MRO顺序的使用

多继承以及MRO顺序 1. 单独调用父类的方法 # coding=utf-8 print("******多继承使用类名.__init__ 发生的状态******") class...

Python中几种导入模块的方式总结

模块内部封装了很多实用的功能,有时在模块外部调用就需要将其导入。常见的方式有如下几种: 1 . import >>> import sys >>>...

详解python单例模式与metaclass

单例模式的实现方式 将类实例绑定到类变量上 class Singleton(object): _instance = None def __new__(cls, *args...

Python中type的构造函数参数含义说明

测试代码如下: 复制代码 代码如下:  class ModelMetaClass(type):      def __new__(cls...

10 行Python 代码实现 AI 目标检测技术【推荐】

10 行Python 代码实现 AI 目标检测技术【推荐】

只需10行Python代码,我们就能实现计算机视觉中目标检测。 from imageai.Detection import ObjectDetection import os ex...