文章目录
- 问题描述
- 图片转base64
- base64转图片
- 图片转base64字符串
- base64字符串转图片
- 二进制图片转base64字符串
- 封装
- 参考文献
问题描述
Python 图片转 base64
base64 是一种用于传输 8Bit 字节码的编码方式,基于 64 个可打印字符来表示二进制数据
1.jpg
图片转base64
读取图片二进制数据,用 base64 加密(结果仍是 bytes 类型),保存
import base64
encoded = base64.b64encode(open('1.jpg', 'rb').read())
print(encoded)
open('1.txt', 'wb').write(encoded) # 保存
base64转图片
import base64
decoded = base64.b64decode(open('1.txt', 'rb').read())
open('2.jpg', 'wb').write(decoded) # 保存
图片转base64字符串
import base64
encoded = base64.b64encode(open('1.jpg', 'rb').read())
print(encoded.decode())
# /9j/4QAwRXhpZgAATU0AKgAAAAgAAQExAAIAAAAOAAAAGgAAAAB3d3cubWVpdHUuY29tAP/bAEMAAgEBAQEBAgEBAQICAgICBAMCAgICBQQEAwQGBQYGBgUGBgYHCQgGBwkHBgYICwgJCgoKCgoGCAsMCwoMCQoKCv/bAEMBAgICAgICBQMDBQoHBgcKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCv/AABEIADIAMgMBEQACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv/xAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGi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LaTyIrxSMjrjGCDgjGOK+yjl94q6OqWOfM7HtfgWWRv+CQ2o6g0jGeX4R3Syzk/O4XWblQC3UgLwPQcVwZml/rlg1/e/RHhYJv6niv8X/th8cfD2OOLw4Z4o1V47m0aN1GCrZbkHsa/U4/AfP1v4iX9bHu/7D+k6VHo+u6tHplut0fEF0puRCokx5h43YzivyPjWpU/tXku7W26fcfrvB9OmsmhOyv36n1h4fAe1iLjJDAjPbmvjX8J7OL+JnoX7XwE/wCwPKZxvMfjDRjHv52kz4OPTgkfQmvpsk1mvn+R+QYj3eJHb+V/kfCfjq3t5viboyTQI4/tFIMMoP7pGLIn+6p5A6A8ivXyht05+p9bm8YwpQ5Vb3f0R8o6/fXs2u3s015KztdyFmaQkkljkk19ckrHhpKx/9k='
decoded = decoded.encode('raw_unicode_escape') # str转bytes
decoded = base64.b64decode(decoded)
open('2.jpg', 'wb').write(decoded) # 保存
二进制图片转base64字符串
requirements.txt
python-magic
python-magic-bin;platform_system=="Windows"
安装
pip install -r requirements.txt
代码
import base64
import magic
bytes = open('1.jpg', 'rb').read()
mimetype = magic.from_buffer(bytes, mime=True)
prefix = 'data:{};base64,'.format(mimetype)
decoded = prefix + base64.b64encode(bytes).decode()
print(decoded)
# data:image/jpeg;base64,/9j/4QAwRXhpZgAATU0AKgAAAAgAAQExAAIAAAAOAAAAGgAAAAB3d3cubWVpdHUuY29tAP/bAEMAAgEBAQEBAgEBAQICAgICBAMCAgICBQQEAwQGBQYGBgUGBgYHCQgGBwkHBgYICwgJCgoKCgoGCAsMCwoMCQoKCv/bAEMBAgICAgICBQMDBQoHBgcKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCv/AABEIADIAMgMBEQACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8C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PKZxvMfjDRjHv52kz4OPTgkfQmvpsk1mvn+R+QYj3eJHb+V/kfCfjq3t5viboyTQI4/tFIMMoP7pGLIn+6p5A6A8ivXyht05+p9bm8YwpQ5Vb3f0R8o6/fXs2u3s015KztdyFmaQkkljkk19ckrHhpKx/9k=
base64图片在线转换
封装
TODO
- 封装成函数
- 检测是否成功
参考文献
- base64 数据编码 — Python 文档
- Python解析u字符串,x字符串,十六进制字符串
- Python文件类型识别——python-magic