-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQRcodeGenerator.py
More file actions
56 lines (41 loc) · 1.73 KB
/
QRcodeGenerator.py
File metadata and controls
56 lines (41 loc) · 1.73 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
44
45
46
47
48
49
50
51
52
53
54
55
56
import qrcode
import os
import pandas as pd
from PIL import ImageDraw, ImageFont
df = pd.read_excel('ActionDescriptionsShortened.xlsx')
data = df.to_numpy()
font = ImageFont.truetype(".Fonts/TimesNewRomanBold.ttf", size=40)
def camelCase(st):
output = ''.join(x for x in st.title() if x.isalnum())
return output[0].lower() + output[1:]
def makeCheckFolder(videoFileName):
if not os.path.exists(folderName):
os.mkdir(folderName)
os.chdir(folderName)
folderName = "./QRPics/"
makeCheckFolder(folderName)
actionCount = 0
for action in data:
qr = qrcode.QRCode(
version=5, #Dimension of QR Code
error_correction=qrcode.constants.ERROR_CORRECT_H, #About 30% or less errors can be corrected. (Max)
box_size=20, #Num of pixels each box is
border=3, #How many boxes make up size of border
)
if not action[2] == "-":
QRCodeData = action[0] + " - " + action[2]
fileName = str(actionCount) + "_" + camelCase(action[0] + " " + action[2]) + ".png"
else:
QRCodeData = action[0]
fileName = str(actionCount) + "_" + camelCase(action[0]) + ".png"
qr.add_data(QRCodeData)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
drawImg = ImageDraw.Draw(img)
#drawImg.text((0,0), "TEST", size=20)
drawImg.text((img.size[0]/2 - font.getsize(QRCodeData)[0]/2,
img.size[1]-font.getsize(QRCodeData)[1]*1.25), QRCodeData, font=font)
#img.size[0]/2, img.size[1]*0.9
img.save(fileName)
actionCount+=1
print("Saved QR Code {} out of {}".format(actionCount, len(data)))