Spaces:
Runtime error
Runtime error
Update qr.py
Browse files
qr.py
CHANGED
@@ -4,7 +4,13 @@ import cv2
|
|
4 |
import os
|
5 |
from PIL import Image
|
6 |
|
7 |
-
def make_qr(txt=None,data=None,im_size=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
if txt != None and txt != "" and data != None:
|
9 |
f = Image.open(f'{data}')
|
10 |
f.thumbnail((im_size,im_size))
|
@@ -12,7 +18,9 @@ def make_qr(txt=None,data=None,im_size=None):
|
|
12 |
imr = open(f'tmp.jpg','rb')
|
13 |
out = f'{txt}+++{base64.b64encode(imr.read())}'
|
14 |
print (f'txt+data {out}')
|
15 |
-
|
|
|
|
|
16 |
img1.save("im.png")
|
17 |
return "im.png"
|
18 |
if txt == None or txt == "" and data != None:
|
@@ -22,14 +30,18 @@ def make_qr(txt=None,data=None,im_size=None):
|
|
22 |
imr = open(f'tmp1.jpg','rb')
|
23 |
out = f'+++{base64.b64encode(imr.read())}'
|
24 |
print (f'data {out}')
|
25 |
-
|
|
|
|
|
26 |
img1.save("im1.png")
|
27 |
return "im1.png"
|
28 |
|
29 |
if txt != None and txt != "" and data == None:
|
30 |
out = f'{txt}'
|
31 |
print (f'txt {out}')
|
32 |
-
|
|
|
|
|
33 |
img1.save("im2.png")
|
34 |
return "im2.png"
|
35 |
|
|
|
4 |
import os
|
5 |
from PIL import Image
|
6 |
|
7 |
+
def make_qr(txt=None,data=None,im_size=None,color_f=None,color_b=None):
|
8 |
+
|
9 |
+
qrm = qr.QRCode(box_size=10,error_correction=qr.constants.ERROR_CORRECT_H)
|
10 |
+
if color_f == None:
|
11 |
+
color_f = "#000"
|
12 |
+
if color_b == None:
|
13 |
+
color_b = "#fff"
|
14 |
if txt != None and txt != "" and data != None:
|
15 |
f = Image.open(f'{data}')
|
16 |
f.thumbnail((im_size,im_size))
|
|
|
18 |
imr = open(f'tmp.jpg','rb')
|
19 |
out = f'{txt}+++{base64.b64encode(imr.read())}'
|
20 |
print (f'txt+data {out}')
|
21 |
+
qrm.add_data(out)
|
22 |
+
qrm.make(fit=True)
|
23 |
+
img1 = qrm.make_image(fill_color=color_f, back_color=color_b)
|
24 |
img1.save("im.png")
|
25 |
return "im.png"
|
26 |
if txt == None or txt == "" and data != None:
|
|
|
30 |
imr = open(f'tmp1.jpg','rb')
|
31 |
out = f'+++{base64.b64encode(imr.read())}'
|
32 |
print (f'data {out}')
|
33 |
+
qrm.add_data(out)
|
34 |
+
qrm.make(fit=True)
|
35 |
+
img1 = qrm.make_image(fill_color=color_f, back_color=color_b)
|
36 |
img1.save("im1.png")
|
37 |
return "im1.png"
|
38 |
|
39 |
if txt != None and txt != "" and data == None:
|
40 |
out = f'{txt}'
|
41 |
print (f'txt {out}')
|
42 |
+
qrm.add_data(out)
|
43 |
+
qrm.make(fit=True)
|
44 |
+
img1 = qrm.make_image(fill_color=color_f, back_color=color_b)
|
45 |
img1.save("im2.png")
|
46 |
return "im2.png"
|
47 |
|