-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqr.py
More file actions
43 lines (36 loc) · 1.42 KB
/
qr.py
File metadata and controls
43 lines (36 loc) · 1.42 KB
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
42
43
import qrcode
from qrcode.image.styledpil import StyledPilImage
def generate_qr_code():
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_H,
box_size=10,
border=2,
)
url = input('Insert URL or text: ')
user_have_logo = input('Want to add a logo to your QR code? (Y/N): ').strip().lower()
qr.add_data(url)
qr.make(fit=True)
if user_have_logo == 'y':
logo = input('Insert your logo file name: ')
qr_img = qr.make_image(image_factory=StyledPilImage, embedded_image_path=logo)
else:
custom_color = input('Want to customize your QR Code? (Y/N): ').strip().lower()
if custom_color == 'y':
foreground = input('Foreground color: ')
background = input('Background color: ')
qr_img = qr.make_image(fill_color=foreground, back_color=background)
else:
qr_img = qr.make_image(fill_color='black', back_color='white')
format_choice = input('Choose the format to save the QR code (PNG/SVG/PDF): ').strip().lower()
if format_choice == 'png':
qr_img.save('qrcode.png')
elif format_choice == 'svg':
qr_img.save('qrcode.svg')
elif format_choice == 'pdf':
qr_img.save('qrcode.pdf')
else:
print('Invalid format choice. Saving as PNG by default.')
qr_img.save('qrcode.png')
if __name__ == '__main__':
generate_qr_code()