-
Notifications
You must be signed in to change notification settings - Fork 0
/
patina.py
42 lines (33 loc) · 1011 Bytes
/
patina.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import base64
import io
import os
import flask
from PIL import Image
from flask import Flask, render_template, request, flash, redirect
from artifacts.add_patina import jpegBlur
app = Flask(__name__)
@app.route("/load", methods=['POST'])
def load():
try:
if 'image' not in request.files:
print('No file part')
return "No files"
file = request.files['image']
except Exception as err:
print('err')
return "Unable to retried the dank memes"
im = jpegBlur(Image.open(io.BytesIO(file.read())), 8, True, 5)
rawBytes = io.BytesIO()
im.save(rawBytes, "JPEG")
rawBytes.seek(0)
img_base64 = base64.b64encode(rawBytes.read())
response = {
"image": img_base64.decode(),
"message": "Image is BASE 64 encoded"
}
return response, 200
@app.route("/")
def index():
return render_template('index.html')
if __name__ == "__main__":
app.run(host='0.0.0.0', port=os.environ.get('PORT', 5000), debug=True)