def build_image(image_data):
template = Image.open("path/to/file/template.jpg")
draw = ImageDraw.Draw(template)
draw.text("(553,431)", f"{image_data.text}", fill=4324234, font=font)
file = InMemoryUploadedFile(template, None, 'result.jpg', 'image/jpeg', template.tell, None)
return FileResponse(file, as_attachment=True, filename='result.jpg')
I need to return the image that was modified, without saving it to the database. The above code gives the following error:
A server error occurred. Please contact the administrator.
- I also tried the following option:
rea_response = HttpResponse(template, content_type='image/png')
rea_response['Content-Disposition'] = 'attachment; filename={}'.format('result.png')
return rea_response
But in this case, I get a corrupted file. (This format is not supported).
django==3.0.6