-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqr_code.py
39 lines (31 loc) · 1005 Bytes
/
qr_code.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
# pyinstaller --onefile --hidden-import=qrcode --hidden-import=PIL qr_code.py
# auto-py-to-exe
import sys
import qrcode
from PIL import Image
def generate_qr(data, output_file, width, height):
# Create QR code instance
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
# Add data to the QR code
qr.add_data(data)
qr.make(fit=True)
# Create an image from the QR Code instance
img = qr.make_image(fill='black', back_color='white')
# Resize the image
img = img.resize((width, height), Image.Resampling.LANCZOS)
# Save the image
img.save(output_file)
if __name__ == "__main__":
if len(sys.argv) != 5:
print("Usage: generate_qr.py <data> <output_file> <width> <height>")
sys.exit(1)
data = sys.argv[1]
output_file = sys.argv[2]
width = int(sys.argv[3])
height = int(sys.argv[4])
generate_qr(data, output_file, width, height)