forked from ravi5175/IAWT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
84 lines (68 loc) · 3.15 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
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 7 19:23:34 2020
Project-Image Authentication Using Water Marking Technique
Section-Main
@author: RAVI
"""
from flask import Flask,render_template,request,url_for,redirect,flash
from flask_uploads import UploadSet,IMAGES
import matplotlib.pyplot as plt
import os
import img_io as img
import key_io
app = Flask(__name__)
"""app configuration"""
app.config["UPLOADED_PHOTOS_DEST"]=os.path.join('static','image','upload')
app.config["WATERMARK_UPLOAD"]=os.path.join('static','image','watermark')
app.config["WATERMARKED_UPLOAD"]=os.path.join('static','image','watermarked')
app.config["ALLOWED_IMAGE_EXTENSIONS"]=["PNG","JPG","JPEG","GIF"]
app.config['MAX_CONTENT_LENGTH'] = 50 * 1024 * 1024
ret_wm=os.path.join('static','image','watermark')
images=UploadSet("images",IMAGES)
@app.route("/", methods=["GET", "POST"])
def home():
if request.method == "POST":
if 'encrypt' in request.form:
return redirect(url_for("encryptor"))
if 'decrypt' in request.form:
return redirect(url_for("decryptor"))
return render_template("index.html")
@app.route("/encryptor", methods=["GET", "POST"])
def encryptor():
if request.method == "POST":
if request.files:
image = request.files["image_file"]
watermark=None
watermark=request.files["watermark_file"]
image.save(os.path.join(app.config["UPLOADED_PHOTOS_DEST"], image.filename))
watermark.save(os.path.join(app.config["WATERMARK_UPLOAD"], watermark.filename))
key=request.form.get("key")
imgname=image.filename
if 'encrypt' in request.form:
image=img.insert_lsb(os.path.join(app.config["UPLOADED_PHOTOS_DEST"], imgname),os.path.join(app.config["WATERMARK_UPLOAD"], watermark.filename),os.path.join(app.config["WATERMARKED_UPLOAD"], image.filename),key)
psnr=img.print_psnr(os.path.join(app.config["UPLOADED_PHOTOS_DEST"], imgname), os.path.join(app.config["WATERMARKED_UPLOAD"], imgname))
return redirect(url_for("encryption_output",img=imgname,psnr=psnr))
return render_template("encryption.html")
@app.route("/decryptor", methods=["GET", "POST"])
def decryptor():
if request.method == "POST":
if request.files:
image = request.files["watermarked_file"]
image.save(os.path.join(app.config["UPLOADED_PHOTOS_DEST"], image.filename))
key=request.form.get("key")
imgname=image.filename
if 'decrypt' in request.form:
img.extract_lsb(os.path.join(app.config["UPLOADED_PHOTOS_DEST"], imgname),os.path.join(ret_wm,imgname),key)
return redirect(url_for("decryption_output",img=imgname))
return render_template("decryption.html")
@app.route("/encryption_output/<img>/<psnr>", methods=["GET", "POST"])
def encryption_output(img,psnr):
return render_template("encryption_output.html",image=img,psnr=psnr)
@app.route("/decryption_output/<img>", methods=["GET", "POST"])
def decryption_output(img):
return render_template("decryption_output.html",image=img)
if __name__=="__main__":
_host='127.0.0.1'
_port=5000
app.run(host=_host,port=_port,debug=True)