generating qr codes and serving them as images

master
Marek Baczynski 6 years ago
parent 7153e9eb82
commit df0809cda9

Binary file not shown.

22
qr.py

@ -1,10 +1,14 @@
from flask import Flask, Response, redirect, url_for, request, session, abort, render_template
from flask import Flask, Response, redirect, url_for, request, session, abort, render_template, send_file
from flask_login import LoginManager, UserMixin, login_required, login_user, logout_user, current_user
from PIL import Image, ImageFont, ImageDraw
from io import BytesIO
import qrcode
import json
import datetime
import re
app = Flask(__name__)
systemURL = 'http://192.168.0.11:5000/'
with open('links.json', 'r') as infile:
links = json.load(infile)
@ -23,6 +27,20 @@ def codeLink(code):
return None
return links[code]['url']
def serveImage(img):
img_io = BytesIO()
img.save(img_io, 'PNG')
img_io.seek(0)
return send_file(img_io, mimetype='image/png')
@app.route('/code/<code>')
def serveCode(code):
code = code[:code.find('.')]
if codeValidation(code) is False:
return send_file('static/invalid.png', mimetype='image/png')
img = qrcode.make(systemURL + code)
return serveImage(img)
@app.route("/edit", methods=['GET', 'POST'])
def edit():
code = request.form.get("code")

@ -12,6 +12,7 @@ Python, and the following packages:
* flask
* flask-login
* qrcode
* pillow
##Work in progress
The system is currently under initial development, and is **not** operational.

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Loading…
Cancel
Save