41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
import qrcode
|
|
import argparse
|
|
import os
|
|
|
|
def main(input_text, output_filename):
|
|
# Add .png extension if not present
|
|
if not output_filename.endswith(".png"):
|
|
output_filename += ".png"
|
|
|
|
# Create a QR code object
|
|
qr = qrcode.QRCode(
|
|
version=1,
|
|
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
|
box_size=10,
|
|
border=0,
|
|
)
|
|
|
|
# Add the input data to the QR code object
|
|
qr.add_data(input_text)
|
|
|
|
# Make the QR code
|
|
qr.make(fit=True)
|
|
|
|
# Create an image object to store the generated QR code
|
|
img = qr.make_image(fill_color="black", back_color="white")
|
|
|
|
# Save the QR code image to a file
|
|
img.save(output_filename)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# Set up the argument parser
|
|
parser = argparse.ArgumentParser(description="Generate a QR code from input text.")
|
|
parser.add_argument("-i", "--input", required=True, help="Text to be embedded in the QR code.")
|
|
parser.add_argument("-o", "--output", required=True, help="Filename for the output image.")
|
|
|
|
# Parse the command-line arguments
|
|
args = parser.parse_args()
|
|
|
|
# Call the main function with the provided arguments
|
|
main(args.input, args.output) |