-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
65 lines (50 loc) · 2.07 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
from Backend import encode,decrypt
import numpy
from numpy import asarray
from PIL import Image,ImageOps
import os
from flask import Flask, flash, request, redirect, url_for, send_from_directory, render_template,send_file
from werkzeug.utils import secure_filename
UPLOAD_FOLDER = os.path.dirname(os.path.abspath(__file__)) + '/uploads/'
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return 'No file part'
file = request.files['file']
# if user does not select file, browser also
# submit an empty part without filename
if file.filename == '':
return render_template('index.html', error='No image uploaded!')
if file and allowed_file(file.filename):
file.save(os.path.join(app.config['UPLOAD_FOLDER'],'download.jpg'))
if request.form['go']=='encrypt':
return redirect(url_for('image'))
return redirect(url_for('decode1'))
else:
return render_template('index.html', error='Please upload an image file')
return render_template('index.html')
@app.route('/image', methods=['GET', 'POST'])
def image():
if request.method == 'POST':
image1 = Image.open(UPLOAD_FOLDER+'download.jpg')
msg=request.form['msg']
x=encode(image1, msg)
x.convert('RGB').save(UPLOAD_FOLDER+'new1.png')
return send_file(UPLOAD_FOLDER+'new1.png', as_attachment=True)
return render_template('encodepage.html')
@app.route('/decode')
def decode1():
image1 = Image.open(UPLOAD_FOLDER+'download.jpg')
msg1= decrypt(image1)
return render_template('about.html',msg=msg1)
if __name__ == '__main__':
app.run(debug = True)