-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQR_Code.py
More file actions
28 lines (23 loc) · 940 Bytes
/
QR_Code.py
File metadata and controls
28 lines (23 loc) · 940 Bytes
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
import qrcode
import sys
# Function to generate QR code from text and save as JPG
def generate_qr_code(text, filename="qrcode.png"):
# Create a QR Code instance
qr = qrcode.QRCode(
version=1, # version parameter controls the size of the QR Code
error_correction=qrcode.constants.ERROR_CORRECT_H, # Error correction level
box_size=10, # Size of each box in the QR code grid
border=4, # Thickness of the border (minimum is 4)
)
# Add data to the QR code
qr.add_data(text)
qr.make(fit=True)
# Create an image from the QR code instance
img = qr.make_image(fill_color="black", back_color="white")
# Save the image as a JPG file
img.save(filename)
print(f"QR Code saved as {filename}")
# Example usage
text_input = input("Enter the text to encode in the QR code: ")
generate_qr_code(text_input)
input("Press Enter to continue...")