You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
623 B
22 lines
623 B
4 years ago
|
from io import BytesIO
|
||
|
import qrcode
|
||
|
from flask import send_file
|
||
|
|
||
|
def generate_qr_code(url):
|
||
|
qr = qrcode.QRCode(
|
||
|
version=None,
|
||
|
error_correction=qrcode.constants.ERROR_CORRECT_M,
|
||
|
box_size=30,
|
||
|
border=4,
|
||
|
)
|
||
|
qr.add_data(url)
|
||
|
qr.make(fit=True)
|
||
|
return qr.make_image(fill_color='black', back_color='white')
|
||
|
|
||
|
def serve_pil_image(pil_img):
|
||
|
# Source: https://stackoverflow.com/questions/7877282/how-to-send-image-generated-by-pil-to-browser
|
||
|
img_io = BytesIO()
|
||
|
pil_img.save(img_io, 'PNG', quality=70)
|
||
|
img_io.seek(0)
|
||
|
return send_file(img_io, mimetype='image/png')
|