-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeqr
58 lines (45 loc) · 1.61 KB
/
makeqr
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
# import modules
import argparse
import qrcode
from PIL import Image
from helpers import resize_logo, change_logo_color
# executes when your script is called from the command-line
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Embed a logo in a QR code')
# arg for logo image
parser.add_argument("--logo", help='The logo image to embed in the QR code')
# arg for URL or text
parser.add_argument("--url", default='https://www.geeksforgeeks.org/', help='The URL or text to encode in the QR code')
# arg for color
parser.add_argument("--color", default='Green', help='The color of the QR code')
# arg for base width
parser.add_argument("--basewidth", default=100, help='The base width of the logo image')
# parse the arguments
args = parser.parse_args()
logo_file = args.logo
url = args.url
color = args.color
basewidth = int(args.basewidth)
QRcode = qrcode.QRCode(
error_correction=qrcode.constants.ERROR_CORRECT_H
)
# adding URL or text to QRcode
QRcode.add_data(url)
# generating QR code
QRcode.make()
# adding color to QR code
QRimg = QRcode.make_image(
fill_color=color, back_color='white').convert('RGB')
# load the logo image
if (args.logo):
logo = Image.open(logo_file)
logo_with_color = change_logo_color(logo, color)
resized_logo = resize_logo(logo_with_color, basewidth)
pos = ((QRimg.size[0] - basewidth) // 2,
(QRimg.size[1] - basewidth) // 2)
QRimg.paste(resized_logo, pos)
file_name = f"{logo_file}_with_QR_code.png" if logo else f"QR_code.png"
# save the QR code generated
QRimg.save(file_name)
print('QR code generated!')