#!/usr/bin/env python3 from qrcode import QRCode, constants #Used to generate the QR from base64 import b64encode #Used to encode the generated QR as base64, to directly insert it into the HTML from io import BytesIO #Needed for base64 encoding of the image from PIL import Image #Needed for QR generation def makeQR(text): #This function is used to create a QR code and encode it base64, if you make a new shortlink qr = QRCode( #QR generation variables version=1, error_correction=constants.ERROR_CORRECT_L, box_size=10, border=1, ) qr.add_data(text) #The URL is in the text variable qr.make(fit=True) #Generate the QR img = qr.make_image(fill_color="black", back_color="white") #Encode the WR as base 64 with BytesIO() as buffer: img.save(buffer, 'jpeg') return b64encode(buffer.getvalue()).decode() if (__name__ == "__main__"): print("This file is not made fore direct call, please run the main.py") exit()