diff --git a/.gitignore b/.gitignore index 140f8cf..5dbf259 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ *.so +*.swp +*/__pycache__ +flask/static diff --git a/flask/app.py b/flask/app.py new file mode 100644 index 0000000..ccedd6c --- /dev/null +++ b/flask/app.py @@ -0,0 +1,46 @@ +from flask import Flask, render_template, request, redirect, url_for +from PIL import Image +import os + +valid_height=800 + +app = Flask(__name__) +app.config['UPLOAD_FOLDER'] = 'static/uploads' + +# Ensure the upload directory exists +if not os.path.exists(app.config['UPLOAD_FOLDER']): + os.makedirs(app.config['UPLOAD_FOLDER']) + +@app.route('/', methods=['GET', 'POST']) +def upload_image(): + if request.method == 'POST': + if 'image' not in request.files: + return redirect(request.url) + file = request.files['image'] + + if file.filename == '': + return redirect(request.url) + if file: + extension = os.path.splitext(file.filename)[1] + filepath = os.path.join(app.config['UPLOAD_FOLDER'], "upload" + extension) + + file.save(filepath) + + # Process image # + height = Image.open(filepath).height + + valid = False + if height == valid_height: + valid = True + ################# + + return render_template('image.html', filename="upload"+extension, height=height, valid=valid) + return render_template('image.html', filename=None) + +@app.route('/uploads/') +def uploaded_file(filename): + return redirect(url_for('static', filename='uploads/' + filename)) + +if __name__ == "__main__": + app.run(debug=True) + diff --git a/flask/templates/base.html b/flask/templates/base.html new file mode 100644 index 0000000..b926191 --- /dev/null +++ b/flask/templates/base.html @@ -0,0 +1,35 @@ + + + + + + Image Upload + + + + + +
+
Text
+
Image
+
QR
+
Barcode
+
+ + {% block content %} + {% endblock %} + + + + diff --git a/flask/templates/image.html b/flask/templates/image.html new file mode 100644 index 0000000..68d9179 --- /dev/null +++ b/flask/templates/image.html @@ -0,0 +1,19 @@ +{% extends "base.html" %} + +{% block content %} +

Upload Image

+
+ + +
+ {% if filename %} +

Uploaded Image:

+ Uploaded Image + {% if valid %} +

Height: {{ height }} px

+ {% else %} +

Height: {{ height }} px

+ {% endif %} + {% endif %} +{% endblock %} +