[英]Is there any Python method to convert base64 encoded string to Image
I'm sending the file from PHP to python server which contains an Image Encoded String I am reading it in python and write the image in a folder.我正在将文件从 PHP 发送到 python 服务器,其中包含一个图像编码字符串我正在用 python 读取它并将图像写入一个文件夹中。 The
image.jpg
file appears in the folder but can't be displayed and the file created in the folder shows 0-byte file size. 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))
open file in 'rb' mode so it will write an img file以'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.