python 用base64 对图片文件的编码和解码处理

用base64 对图片文件的编码和解码处理

python 用base64 对图片文件的编码和解码处理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import base64

def convert(image):
    f = open(image)
    img_raw_data = f.read()
    f.close()

    img_b64_string = base64.b64encode(img_raw_data)
    convert_img_raw_data = base64.b64decode(img_b64_string)

    t = open("example.png", "w+")
    t.write(convert_img_raw_data)
    t.close()

if __name__ == "__main__":
    convert("test.png")

本文网址: https://py.youbbs.org/topic/139.html 转摘请注明来源

Suggested Topics

python编程中常用的12种基础知识总结

python编程中常用的12种基础知识总结:正则表达式替换,遍历目录方法,列表按列排序、去重,字典排序,字典、列表、字符串互转,时间对象操作,命令行参数解析(getopt),print 格式化输出,进制转换,Python调用系统命令或者脚本,Python 读写文件。...

给ssdb python 接口提速

SSDB 是个新兴的数据库,其数据库的特点简单,性能高效,有好多python 接口,个人比较后选择一个最理想的,但还有提速空间,这里仅作经验分享。...

python 使用 magic 从文件内容判断文件类型

使用 python-magic 库可以轻松识别文件的类型,python-magic是libmagic文件类型识别库的python接口。libmagic通过根据预定义的文件类型列表检查它们的头文件来识别文件类型。 ...

原生 js 实现选择图片后本地预览

在web 编程里有时候会需要这样的功能,在 file 控件里选择图片后需要实时预览,而不用上传到服务器。可以用 `URL.createObjectURL()` 函数实现。...

Leave a Comment