Spaces:
Runtime error
Runtime error
Update crypt.py
Browse files
crypt.py
CHANGED
@@ -8,13 +8,75 @@ import base58
|
|
8 |
import base64
|
9 |
import cv2
|
10 |
import numpy as np
|
11 |
-
from PIL import Image
|
12 |
import os
|
13 |
import uuid as uniq
|
14 |
import qrcode as qr
|
15 |
-
|
16 |
import math
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
|
|
18 |
############### qr ######################
|
19 |
|
20 |
def make_qr(txt=None,data=None,im_size=None,color_f=None,color_b=None):
|
@@ -242,7 +304,7 @@ def encrypt_text(data,pub_im,priv_im,address):
|
|
242 |
add_label = str(address)
|
243 |
add_label = add_label.strip("b").strip("'")
|
244 |
trans_im1=make_qr(txt=address, color_b="#ECFD08")
|
245 |
-
private_key_im =
|
246 |
private_key_im.save("private_key_im.png")
|
247 |
enc_qr = conv_im("private_key_im.png",data=file_data)
|
248 |
file.close()
|
|
|
8 |
import base64
|
9 |
import cv2
|
10 |
import numpy as np
|
|
|
11 |
import os
|
12 |
import uuid as uniq
|
13 |
import qrcode as qr
|
|
|
14 |
import math
|
15 |
+
from PIL import ImageFont, ImageDraw, Image
|
16 |
+
|
17 |
+
def process(img,font_text,font_fac,font_x,font_y,font_col,font_op):
|
18 |
+
img.save('tmp.png')
|
19 |
+
|
20 |
+
img = Image.open('tmp.png').convert("RGBA")
|
21 |
+
im=img
|
22 |
+
#im=Image.open(img)
|
23 |
+
txt = Image.new('RGBA', im.size, (255,255,255,0))
|
24 |
+
|
25 |
+
w, h = im.size
|
26 |
+
print (f'FONT COLOR: {font_col}')
|
27 |
+
#t_fill = ("#"+"E6"+f"{font_col.strip('#')}")
|
28 |
+
|
29 |
+
#t_fill = (font_col)
|
30 |
+
h1 = font_col.strip("#")
|
31 |
+
rgb_tup = tuple(int(h1[i:i+2], 16) for i in (0, 2, 4))
|
32 |
+
print (rgb_tup)
|
33 |
+
a,b,c = rgb_tup
|
34 |
+
t_fill = (a,b,c,font_op)
|
35 |
+
|
36 |
+
print (f'FONT COLOR: {t_fill}')
|
37 |
+
|
38 |
+
#x = int(w-font_x)
|
39 |
+
#y = int(h-font_y)
|
40 |
+
x = int(font_x)
|
41 |
+
y = int(font_y)
|
42 |
+
draw = ImageDraw.Draw(txt)
|
43 |
+
text = f'{font_text}'
|
44 |
+
font_size=font_fac
|
45 |
+
font = ImageFont.truetype("./fonts/SansitaOne.ttf", int(font_size))
|
46 |
+
size = font.getsize(text)
|
47 |
+
draw.text((x-size[0]/2, y),text, font = font, fill=t_fill)
|
48 |
+
|
49 |
+
#txt.putalpha(128)
|
50 |
+
|
51 |
+
combined = Image.alpha_composite(im, txt)
|
52 |
+
return combined
|
53 |
+
|
54 |
+
def textover(im,txt1="",txt2=""):
|
55 |
+
#im.save('tmp.png')
|
56 |
+
|
57 |
+
im = Image.open(im)
|
58 |
+
inp=1
|
59 |
+
hh=0
|
60 |
+
hhh=25
|
61 |
+
#cnt = len(inp)
|
62 |
+
cnt = inp
|
63 |
+
font_a = 30
|
64 |
+
font_b = 10
|
65 |
+
if cnt >0:
|
66 |
+
font_a = font_a + (cnt * 2)
|
67 |
+
font_b = font_b + (cnt * 2)
|
68 |
+
#hh = hh-int(cnt/2)
|
69 |
+
hhh = hhh+int(cnt/2)
|
70 |
+
w,h = im.size
|
71 |
+
print (w)
|
72 |
+
print (h)
|
73 |
+
font_x = (w/2)
|
74 |
+
font_y = h-hhh
|
75 |
+
out = process(im,txt1,font_fac=font_a,font_x=font_x,font_y=hh,font_col="#000000",font_op=255)
|
76 |
+
out = process(out,txt2,font_fac=font_b,font_x=font_x,font_y=font_y,font_col="#000000",font_op=255)
|
77 |
+
#out.save("out.png")
|
78 |
|
79 |
+
return out
|
80 |
############### qr ######################
|
81 |
|
82 |
def make_qr(txt=None,data=None,im_size=None,color_f=None,color_b=None):
|
|
|
304 |
add_label = str(address)
|
305 |
add_label = add_label.strip("b").strip("'")
|
306 |
trans_im1=make_qr(txt=address, color_b="#ECFD08")
|
307 |
+
private_key_im = textover(trans_im1, "Transaction",add_label)
|
308 |
private_key_im.save("private_key_im.png")
|
309 |
enc_qr = conv_im("private_key_im.png",data=file_data)
|
310 |
file.close()
|