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://pylist.com/topic/139.html 转摘请注明来源

Suggested Topics

给ssdb python 接口提速

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

在 Ubuntu 16.04.6 LTS 系统上安装 Python 3.6.3

自己的阿里云一个 VPS 用的是系统 Ubuntu 16.04.6 LTS,自带的python版本是 `2.7.12` 与 `3.5.2`,有时候要用到 python `3.6`,又不想卸掉原来版本。下面介绍安装 python 3.6.3 的过程,因为版本较旧,遇到一些坑,这里记录一下。...

Leave a Comment