【Python3】将图片base64编码后保存到程序内部并读取

2020年8月28日01:03:07 评论 9 12728字阅读42分25秒

【Python3】将图片base64编码后保存到程序内部并读取

有些时候,在图片较小时(注意,建议对图片较小时使用,比如几k,或者几十k,否则存不了多少图片数据库就过大或者处理较慢了),我们可以将其转换为base64编码然后保存至数据库,在需要的时候再从数据库中读取以及处理即可转化为图片。

下面是一段将其保存到txt的python代码:

import base64
 
 
def encode_image(img_path: str):
    # 获取图片的字节码
    with open(img_path, 'rb') as img:
        # img_data数据可能混杂其他符号或者不完整,调用时需要检查下
        img_data = base64.b64encode(img.read())
        # print(img_data)
        print(type(img_data))
 
    # 图片太大时,print打印出来的信息会不完整,再写到文件中保存方便后续解码使用
    with open('ceshi.txt', 'wb') as f:  # 临时存的名字,当然,也可以不存名字,直接使用
        f.write(img_data)
 
 
def decode_image(img_str: str):
    # 图片字节码有格式要求,img_str模板:"/9j/4AAQSkZJR+kRXhpZgA=="
    # 把图片解码到本地,需要引用图片的组件直接调用就可以显示了
    # img_str = open(img_str)
    # print(img_str)
    with open(img_str, 'r') as f:
        img_str = f.read()  # 读取全部bai内容为字符串
    print(type(img_str))
    # print(base64.b64decode(img_str))
    with open('123.png', 'wb') as img:  # 读取txt之后要保存到本地的图片名字
        img.write(base64.b64decode(img_str))
 
 
encode_image("001.png")
decode_image("./ceshi.txt")

比如:

import base64

mcj = "iVBORw0KGgoAAAANSUhEUgAAAEoAAAA+CAYAAACMY42mAAAEGWlDQ1BrQ0dDb2xvclNwYWNlR2VuZXJpY1JHQgAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBev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h2KAfnf/7QHRqtXQ9jTKZZDeastJdcRameUE/ReVdohl+94MfxGLzebz40tPA7Gn83OMfw2AqwMl77qGpcMjs7QaHR/kd/0sI9derl69idpE3+II6vI2XqbfVh1gR16LVKPBNdvYq03/KHfm3mXk7kHZJlb5WUBx+ttcgs7hJ6sJPuMym7be2LcXvdNglESRGiO19LEg2DpdboExsJco2apnTe28obI6Go5cncAScwFHagqT43RgMoyTM0q9YwIRBCb+H69v0vspczKoRgRAGy3Zk88MA2bS+teGdAk50hoNlNhxbkCxPe99t3Z12rEQpQ4Vh5sJg2Q9Vbhu34NhvbKy23k1B9CpYHmws/iwv4TxTeftH+Sbsx5wFQBVs+k6xrWca3P7Zr91w+fc7vcPgdkf23QJyp1if2PIdOsMSZTNto/ZdsfLCYCnPgrE3Vtm7KVh+9ouVF84Pp3fxYJnclbn9Ysv2xiq+U95+bb2TeZZ50WDTNt4vL1y2Q7dleCdjn0S4zu3S+3z2rs0KA3G79NuIDzP+tsJ9Mu5U/05l+zT1A8sKg7G30zuV7ar7Pz72cmwshIVAAAAAAElFTkSuQmCC"
with open('头像.png', 'wb') as img:  # 读取txt之后要保存到本地的图片名字
    img.write(base64.b64decode(mcj)) # 得到图片: 头像.png

 

源程序来自于:https://www.machunjie.com/linux/765.html

继续阅读
  • 本文由 发表于 2020年8月28日01:03:07
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接