I'm using flask for my application. I'd like to send an image (dynamically generated by PIL) to client without saving on disk.
Any idea how to do this ?
Here's a version without any temp files and the like (see here):
def serve_pil_image(pil_img):
img_io = StringIO()
pil_img.save(img_io, 'JPEG', quality=70)
img_io.seek(0)
return send_file(img_io, mimetype='image/jpeg')
To use in your code simply do
@app.route('some/route/')
def serve_img():
img = Image.new('RGB', ...)
return serve_pil_image(img)