I am trying to deploy an app that writes and reads png images with Flask. Locally I can run my script with no errors, except when I run it on my server.
I deployed using this guide on DigitalOcean. It uses apache, wsgi and virtualenv.
This an example of my code:
from flask import Flask
from flask import send_file
from PIL import Image
app = Flask(__name__)
img = Image.new('RGB', (200, 100), (255, 255, 255))
return send_file('output.png', mimetype='image/png')
if __name__ == "__main__":
font = ImageFont.truetype("Archive.otf", 60)
You need to use an absolute path, like
/var/www/somedir/somefile. This is because Flask under Apache does not give Python a usable working directory. I would suggest making the path configurable.