Python图片转base64

news/2025/1/12 23:27:30/

文章目录

  • 问题描述
  • 图片转base64
  • base64转图片
  • 图片转base64字符串
  • base64字符串转图片
  • 二进制图片转base64字符串
  • 封装
  • 参考文献

问题描述

Python 图片转 base64

base64 是一种用于传输 8Bit 字节码的编码方式,基于 64 个可打印字符来表示二进制数据

1.jpg




图片转base64

读取图片二进制数据,用 base64 加密(结果仍是 bytes 类型),保存

import base64encoded = base64.b64encode(open('1.jpg', 'rb').read())
print(encoded)
open('1.txt', 'wb').write(encoded)  # 保存




base64转图片

import base64decoded = base64.b64decode(open('1.txt', 'rb').read())
open('2.jpg', 'wb').write(decoded)  # 保存




图片转base64字符串

import base64encoded = base64.b64encode(open('1.jpg', 'rb').read())
print(encoded.decode())
# /9j/4QAwRXhpZgAATU0AKgAAAAgAAQExAAIAAAAOAAAAGgAAAAB3d3cubWVpdHUuY29tAP/bAEMAAgEBAQEBAgEBAQICAgICBAMCAgICBQQEAwQGBQYGBgUGBgYHCQgGBwkHBgYICwgJCgoKCgoGCAsMCwoMCQoKCv/bAEMBAgICAgICBQMDBQoHBgcKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCv/AABEIADIAMgMBEQACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv/xAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgU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NSvK8IRbS/vydn9yXyuj5Wu/GmhWd1LaTyIrxSMjrjGCDgjGOK+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 base64import magicbytes = 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/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEi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LjJDAjPbmvjX8J7OL+JnoX7XwE/wCwPKZxvMfjDRjHv52kz4OPTgkfQmvpsk1mvn+R+QYj3eJHb+V/kfCfjq3t5viboyTQI4/tFIMMoP7pGLIn+6p5A6A8ivXyht05+p9bm8YwpQ5Vb3f0R8o6/fXs2u3s015KztdyFmaQkkljkk19ckrHhpKx/9k=

base64图片在线转换




封装

TODO

  • 封装成函数
  • 检测是否成功




参考文献

  1. base64 数据编码 — Python 文档
  2. Python解析\u字符串,\x字符串,十六进制字符串
  3. Python文件类型识别——python-magic

http://www.ppmy.cn/news/183378.html

相关文章

各地2022年上半年软考考试疫情防控要求汇总-2022-05更新

序号地区考试期间防疫要求简述最新考试防疫通知1四川每场考试前,考生应至少提前1小时到达考点。在考点入场检测处,请考生提前准备好当天本人防疫健康码(绿码)和通信大数据行程卡(绿码)、纸质准考证、有效身…

JavaScript高级

文章目录 今日内容:一、DOM简单学习(为了满足案例要求)1、功能 二、事件简单学习三、BOM:1. 概念:Browser Object Model 浏览器对象模型2. 组成:3. Window:窗口对象案例2:轮播图 4. Location&am…

Android12之MediaCodec参数(二十八)

简介: CSDN博客专家,专注Android/Linux系统,分享多mic语音方案、音视频、编解码等技术,与大家一起成长! 优质专栏:Audio工程师进阶系列【原创干货持续更新中……】🚀 人生格言: 人生从来没有捷径,只有行动才是治疗恐惧和懒惰的唯一良药. ​

http请求走私漏洞原理,利用,检测,防护

目录 什么是请求走私 漏洞成因与常见类型 Keep-Alive&Pipeline CL&TE 常见走私类型

如何学习无线电通联字母解释法和通联术语

如何学习无线电通联字母解释法和通联术语 本人从14年接触无线电,18年开始正式学习,19年获得A证,21年下半年设台。有将近一年处于守听状态,在22年55节后开始了第一次通联。目前正在准备B证的考试。 无线电通联过程中对待英文字母…

GoldenGate案例一则:抽取进程无法捕获数据

GoldenGate故障案例一则: 抽取进程无法无法捕获数据 ⒈ 背景 某软件开发商自己维护的一套Goldengate环境,一共有5个抽取进程,所有的抽取进程状态都为running,但其中的一个抽取进程无法捕获数据变化,该抽取进程所对应的…

mysql jdbc allow_Jdbc Url 设置allowMultiQueries为true和false时底层处理机制研究

一个mysql jdbc待解之谜 关于jdbc url参数 allowMultiQueries 如下的一个普通JDBC示例: String user "root"; String password "root"; String url "jdbc:mysql://localhost:3306"; Connection conn java.sql.DriverManager.getConnection(u…

数据结构导论大题汇总

文章目录 前言:真题汇总搬家了!!!一、应用题二、算法设计题 前言:真题汇总搬家了!!! 自考本科数据结构导论(02142)历年(应用题算法题&#xff09…