繁体   English   中英

是否有任何 Python 方法可以将 base64 编码的字符串转换为 Image

[英]Is there any Python method to convert base64 encoded string to Image

我正在将文件从 PHP 发送到 python 服务器,其中包含一个图像编码字符串我正在用 python 读取它并将图像写入一个文件夹中。 image.jpg文件出现在文件夹中但无法显示,并且文件夹中创建的文件显示为 0 字节文件大小。

import base64
import sys
file=sys.argv[1]
f=open(file)
base_64=f.read()
with open("image.jpg","wb") as fh:
    fh.write(base64.decodebytes(base_64))

以'rb'模式打开文件,以便写入一个img文件

import base64
import sys
file=sys.argv[1]
f=open(file,"rb")
base_64=f.read()
with open("image.jpg","wb") as fh:
    fh.write(base64.decodebytes(base_64))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM