在PHP脚本中显示PIL图像

2024-04-24 03:04:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个生成PIL图像的python脚本。我需要使用curl将这个图片发送到php脚本。我只找到了一种方法:将图像转换为字节数组并以文本形式返回:

# image is a PIL object
from PIL import Image
import io, json

image = Image.open('test.png', mode = 'r')
img_io = io.BytesIO()
image.save(img_io, format='PNG')
byte_array = img_io.getvalue()
print(json({'image':byte_array}))

接下来,我解码这个字节数组并用以下php代码显示图像:

^{pr2}$

但是,我不知道这样可以吗。在

问题是:有没有更正确的方法在php中使用curl获取PIL图像?在


Tags: 方法io图像imageimport脚本jsonimg