-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqrcodeT.py
36 lines (32 loc) · 1.11 KB
/
qrcodeT.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
import qrcode
import numpy as np
def qrcode2text(img):
bindata = np.array(img)[::10,::10] + 0
if bindata.shape[0] % 2 != 0:
bindata.resize((bindata.shape[0]+1,bindata.shape[1]),refcheck=False)
twolines_compress = bindata[::2,:] + 2*bindata[1::2,:]
chars = np.zeros(twolines_compress.shape)
char_table = [' ','▀','▄','█']
chars[twolines_compress==0] = ord(char_table[0])
chars[twolines_compress==1] = ord(char_table[1])
chars[twolines_compress==2] = ord(char_table[2])
chars[twolines_compress==3] = ord(char_table[3])
return chars
def print_qrcode_asText(chars):
for i in range(chars.shape[0]):
for j in range(chars.shape[1]):
print(chr(int(chars[i,j])),end='')
print()
def qrcode_asText(img):
print_qrcode_asText(qrcode2text(img))
def qrcodeT(txt):
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=2,
)
qr.add_data(txt)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
qrcode_asText(img)