Last active
December 25, 2015 21:48
-
-
Save wprudencio/7044729 to your computer and use it in GitHub Desktop.
Simple flask startup.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
start = time.time() | |
from flask import Flask, request,send_file,make_response | |
import Image | |
import urllib2 as urllib | |
from StringIO import StringIO | |
import ImageOps | |
from flask import render_template | |
app = Flask(__name__) | |
//image resize | |
@app.route('/image_resize/') | |
def image_resize(): | |
url_image = request.args.get('url') | |
width = int(request.args.get('width')) | |
height = int(request.args.get('height')) | |
fd = urllib.urlopen(url_image.__str__()) | |
im = Image.open(StringIO(fd.read())) | |
im = ImageOps.fit(im, (width, height), method=Image.ANTIALIAS) | |
im.save('foo.jpg', 'JPEG', quality=20) | |
def wsgi_app(endviron, start_response): | |
start_response('200 OK', [('Content-type', 'image/jpeg')]) | |
return im.tostring('jpeg', 'RGB') | |
print "Took", (time.time() - start) | |
return make_response(wsgi_app) | |
@app.route("/") | |
def hello(): | |
return render_template('index.html') | |
if __name__ == '__main__': | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment