如何使用python cgi将.png文件发送到flex应用程序?
提前致谢...
答案 0 :(得分:3)
如果您只是需要发送现有图像,问题的Python / CGI方面可以像这样简单:
import sys
# Send the Content-Type header to let the client know what you're sending
sys.stdout.write('Content-Type: image/png\r\n\r\n')
# Send the actual image data
with open('path/to/image.png', 'rb') as f:
sys.stdout.write(f.read())
另一方面,如果您使用PIL动态创建图像,则可以按以下方式执行操作:
import sys
import Image, ImageDraw # or whatever
sys.stdout.write('Content-Type: image/png\r\n\r\n')
# Dynamically create an image
image = Image.new('RGB', (100, 100))
# ... etc ...
# Send the image to the client
image.save(sys.stdout, 'PNG')