I want to crop my image file using PIL library and display it using Flask and Jinja.
I have tried this code:
@bp.route('/media/<fname>')
def fetch_media(fname):
...
image = Image.open(path)
cropped_image = image.crop(box)
return cropped_image
This gives a TypeError:
The view function did not return a valid response. The return type must be a string, dict, tuple, Response instance, or WSGI callable, but it was a Image.
How can I return the Image to html page?
Untested, but certainly pretty close to this:
import io
from PIL import Image
from flask import Response
....
....
buffer = io.BytesIO()
cropped_image.save(buffer, format="PNG")
return Response(buffer.getvalue(), mimetype='image/png')
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments