-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQR generator.py
41 lines (35 loc) · 1.33 KB
/
QR generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import qrcode
from PIL import Image
import os
def generate_qr_code(data):
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(data)
qr.make(fit=True)
# Create the QR code image
img = qr.make_image(fill='black', back_color='white')
img.show()
save_option = input("Do you want to download the QR code? (y/n): ")
if save_option.lower() == 'y':
filename = input("Enter the file name (without extension, e.g., my_qr_code): ")
valid_extensions = ['.png', '.jpg', '.jpeg']
file_ext = input("Enter the desired extension (.png, .jpg, .jpeg): ").lower()
# If the extension is not valid, use '.png' as default
if file_ext not in valid_extensions:
print("Invalid extension, using '.png' by default.")
file_ext = '.png'
# Combine the file name and extension
full_filename = filename + file_ext
# Specific path for saving
save_path = os.path.join(r'path', full_filename)
# Save the QR code image
img.save(save_path)
print(f"QR code saved as {save_path}")
else:
print("QR code not saved.")
data = input("Enter the link for the QR code: ")
generate_qr_code(data)