42 lines
974 B
Python
42 lines
974 B
Python
import argparse
|
|
import qrcode
|
|
|
|
from PIL import Image
|
|
|
|
|
|
def generate_qr_code(url, name):
|
|
qr = qrcode.QRCode(
|
|
version=1,
|
|
error_correction=qrcode.constants.ERROR_CORRECT_H,
|
|
box_size=50,
|
|
border=1,
|
|
)
|
|
|
|
qr.add_data(url)
|
|
qr.make(fit=True)
|
|
|
|
img = qr.make_image(fill_color="black", back_color="white")
|
|
|
|
overlay = Image.open("static/rs_koc.webp")
|
|
|
|
if overlay.mode != 'RGBA':
|
|
overlay = overlay.convert('RGBA')
|
|
if img.mode != 'RGBA':
|
|
img = img.convert('RGBA')
|
|
|
|
img.paste(overlay, (420, 420), overlay)
|
|
|
|
output_path = f"output/{name}.png"
|
|
img.save(output_path)
|
|
|
|
print(f"QR Code generated at: {output_path}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('url', help="URL for the QR code")
|
|
parser.add_argument('name', help="Name of the file, do not include extension")
|
|
|
|
args = parser.parse_args()
|
|
|
|
generate_qr_code(args.url, args.name)
|