动态地从PIL提供图像
|
我正在使用PIL(Python图像库)和Paste制作一个非常简单的网页。我有一个仅返回图像标签的函数:
def home(self):
return \'<img src=\"photo\" alt=\"photo\"/>\'
而且我还有一个名为photo的函数(理想情况下)返回要放入img标签的图像:
def photo(self):
img = image_from_PIL # this part works
output = StringIO.StringIO()
img.save(output, \"JPEG\") # saves the image as a StringIO in output
final_img = output.getvalue()
output.close()
# then set headers[\'content-type\'] = \'image/jpeg\' (confirmed this works)
return [final_img]
因此,我知道图像存在于字符串final_img
中,并且内容类型为\“ image / jpeg \”。我希望这能奏效,但是我得到的只是200状态OK响应,大小为0。
我也尝试了许多其他事情,包括:
将字符串转换为二进制并将其吐出来
将标头中的内容长度设置为字符串的长度(和x8,因为每个字符为8位)
如果有什么不同,我的服务器正在使用uWSGI和nginx
我不知道还能尝试什么!谢谢你的帮助。
没有找到相关结果
已邀请:
1 个回复
纤洞需匪
与