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)