-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.py
122 lines (88 loc) · 3.71 KB
/
app.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# app.py
from flask import Flask, flash, request, redirect, url_for, render_template
import urllib.request
import os
from werkzeug.utils import secure_filename
import imageProcess
app = Flask(__name__)
UPLOAD_FOLDER = 'static/uploads/'
temp = imageProcess.PipeLine()
app.secret_key = "secret key"
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
app.config['CURRENT_FILE'] = ''
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/encryptImage', methods=['GET', 'POST'])
def encrypt_image():
if app.config['CURRENT_FILE'] == '':
flash('No picture uploaded')
return render_template('index.html')
temp.encrypt_to_disc(UPLOAD_FOLDER + app.config['CURRENT_FILE'], UPLOAD_FOLDER + "converted_disc.png")
app.config['CURRENT_FILE'] = "converted_disc.png"
return render_template('index.html', filename="converted_disc.png")
@app.route('/decryptImage', methods=['GET', 'POST'])
def decrypt_image():
if app.config['CURRENT_FILE'] == '':
flash('No picture uploaded')
return render_template('index.html')
temp.decrypt_to_picture(UPLOAD_FOLDER + app.config['CURRENT_FILE'], UPLOAD_FOLDER + 'decryptedPic.png')
return render_template('index.html', filename="decryptedPic.png")
@app.route('/uploadImage', methods=['GET', 'POST'])
def upload_image():
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
if file.filename == '':
flash('No image selected for uploading')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
app.config['CURRENT_FILE'] = filename
# print('upload_image filename: ' + filename)
flash('Image successfully uploaded and displayed below')
return render_template('index.html', filename=filename)
else:
flash('Allowed image types are - png, jpg, jpeg, gif')
return redirect(request.url)
# # app.route('/changeImage', methods = ['GET', 'POST'])
# # def change_image(fileName):
# # Get file here
# # filename = secure_filename(file.filename)
# # image = file.get(os.path.join(app.config['UPLOAD_FOLDER'], filename))
# # encrypt the image here
# # encryptedFile = encryptImage(image)
# # save again, get the encrypted file name
# # encryptedFilename =
# # follow logic to render encrypted
# return render_template('encrypted.html', filename=encryptedFilename)
@app.route('/')
def home():
return render_template('create_account.html')
@app.route('/index', methods=['GET', 'POST'])
def image():
return render_template('index.html', upload_image=upload_image)
@app.route('/index', methods=['GET', 'POST'])
def encryptIMG():
return render_template('index.html', encrypt_image=encrypt_image)
@app.route('/index', methods=['GET', 'POST'])
def decryptIMG():
return render_template('index.html', decrypt_image=decrypt_image)
@app.route('/upload')
def upload_file():
return render_template('upload.html')
@app.route('/uploader', methods=['GET', 'POST'])
def uploader():
if request.method == 'POST':
f = request.files['file']
f.save(secure_filename(f.filename))
return 'file uploaded successfully'
@app.route('/display/<filename>')
def display_image(filename):
# print('display_image filename: ' + filename)
return redirect(url_for('static', filename='uploads/' + filename), code=301)
if __name__ == "__main__":
app.run(debug=True)