Created
June 7, 2019 20:42
-
-
Save tommorris/d61baf6a0f6ae56c9c3acf05d2a5983e to your computer and use it in GitHub Desktop.
Google Cloud Function for creating QR codes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io | |
from flask import send_file | |
import qrcode | |
def make_qr(data, box_size=10, border=2): | |
qr = qrcode.QRCode(version=1, | |
error_correction=qrcode.constants.ERROR_CORRECT_L, | |
box_size=box_size, | |
border=border) | |
qr.add_data(data) | |
qr.make(fit=True) | |
img = qr.make_image() | |
img_buf = io.BytesIO() | |
img.save(img_buf) | |
img_buf.seek(0) | |
return img_buf | |
def get_qrimg(request): | |
url = request.args.get('url') | |
box_size = request.args.get('size', 10) | |
border = request.args.get('border', 2) | |
img_data = make_qr(url, box_size, border) | |
return send_file(img_data, mimetype='image/png') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Click==7.0 | |
Flask==1.0.3 | |
itsdangerous==1.1.0 | |
Jinja2==2.10.1 | |
MarkupSafe==1.1.1 | |
Pillow==6.0.0 | |
qrcode==6.1 | |
six==1.12.0 | |
Werkzeug==0.15.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment