【Flask】数字水印Web

写这个的目的是稍微熟悉一下数据在前端和后端是怎么传输的orz

Code

addWaterMarking和testWaterMarking应该是在前一篇
http://blog.csdn.net/birdy_/article/details/78822350

#coding:utf-8

import sys
reload(sys)
sys.setdefaultencoding("utf-8")
import os
from flask import Flask,url_for,render_template,request,url_for,redirect,send_from_directory
from addMark import addWaterMarking
from testMark import testWaterMarking
from werkzeug import secure_filename
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

UPLOAD_FOLDER='home'
ALLOWED_EXTENSIONS=set(['png','jpg','jpeg','gif'])

app=Flask(__name__)
global strMark
strMark = ' '
app.config['UPLOAD_FOLDER']=UPLOAD_FOLDER

def allowed_file(filename):
    return '.' in filename and filename.rsplit('.',1)[1] in ALLOWED_EXTENSIONS

@app.route('/',methods=['GET','POST'])
def upload_file():
    if request.method=='POST':
        file1=request.files['file']
        file2=request.files['file_mask']
        if file1 and allowed_file(file1.filename) and file2 and allowed_file(file2.filename):
            addWaterMarking(file1,file2)
            return redirect(url_for('upload_file'))
    return '''
    <!DOCTYPE html>
    <title>upload new file</title>
    <h1>Add Digital Watermarking</h1>
    <h2>Choose picture</h2>
    <form action="/" method="POST" enctype="multipart/form-data">
    <input type="file" name="file" />
    <h2>Choose Watermarking</h2>
    <form action="/" method="POST" enctype="multipart/form-data">
    <input type="file" name="file_mask" />
    <p>
    <input type="submit" value="handle" />
    </p>
    <a href="test">Test Watermarking</a>
    <p>
    <script type="text/javascript">  
    document.write("<img src='../static/output.png?v="+new Date().getTime()+"'>");   
    </script>  
    </p>
    </form>
    '''


@app.route('/test',methods=['GET','POST'])
def test_file():
    global strMark
    if request.method=='POST':
        file1=request.files['file']
        file2=request.files['file_mask']
        if file1 and allowed_file(file1.filename) and file2 and allowed_file(file2.filename):
            boolMark = testWaterMarking(file1,file2)
            if boolMark == False:
                strMark = 'False'
            else:
                strMark = 'True'
            return redirect(url_for('test_file'))
    return '''
    <!DOCTYPE html>
    <title>upload new file</title>
    <h1>Test Digital Watermarking</h1>
    <h2>Choose picture</h2>
    <form action="/test" method="POST" enctype="multipart/form-data">
    <input type="file" name="file" />
    <h2>Choose Watermarking</h2>
    <form action="/test" method="POST" enctype="multipart/form-data">
    <input type="file" name="file_mask" />
    <p>
    <input type="submit" value="handle" target="/test" />
    </p>
    <a href="/">Add Watermarking</a>
    <p>
    ''' + strMark+  '''
    </p>
    </form>
    '''

@app.route('/uploads/<filename>')
def uploaded_file(filename):
    return send_from_directory(app.config['UPLOAD_FOLDER'],filename)


if __name__ == '__main__':
    strMark = ''
    app.run()

Result

最后结果图(看看这朴实无华的界面)


加入水印的界面

没有图片描述!


检测水印的界面

这里写图片描述

转载于:https://www.cnblogs.com/BirdCage/p/9974023.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值