Created
November 15, 2018 02:35
-
-
Save Ronald-TR/9e99e100d2136132cab0aed8e2c8a48a to your computer and use it in GitHub Desktop.
This file contains 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
from flask import Flask, request, send_from_directory, send_file | |
from PIL import Image, ImageFilter | |
from io import BytesIO | |
import os | |
app = Flask(__name__) | |
@app.route('/') | |
def index(): | |
return '<h1>Olá mundo</h1>' | |
@app.route('/upload', methods=['GET', 'POST']) | |
def upload(): | |
if request.method == 'POST': | |
ofile = request.files['file'] | |
filedir = os.path.join(os.getcwd(), ofile.filename) | |
ofile.save(filedir) | |
return send_from_directory(os.getcwd(), ofile.filename) | |
return ''' | |
<form enctype="multipart/form-data" action="/upload" method="post"> | |
<input type="file" name="file"/> | |
<button type="submit">Enviar</button> | |
</form> | |
''' | |
@app.route('/gaussianblur', methods=['GET', 'POST']) | |
def gaussianblur(): | |
if request.method == 'POST': | |
img = Image.open(request.files.get('image').stream) | |
gaussian = img.filter(ImageFilter.GaussianBlur) | |
bytes_image = BytesIO() | |
gaussian.save(bytes_image, 'PNG', quality=70) | |
bytes_image.seek(0) | |
return send_file(bytes_image, mimetype='image/png') | |
return ''' | |
<form enctype="multipart/form-data" action="/gaussianblur" method="post"> | |
<input type="file" name="image"/> | |
<button type="submit">Enviar</button> | |
</form> | |
''' | |
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