Omnibus commited on
Commit
913b5c9
·
1 Parent(s): e4a6d59

Create overlay.py

Browse files
Files changed (1) hide show
  1. overlay.py +55 -0
overlay.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ from PIL import Image
3
+
4
+
5
+ def textover(im,txt,inp):
6
+ hh=1
7
+ hhh=45
8
+ cnt = len(inp)
9
+ font_a = 30
10
+ font_b = 40
11
+ if cnt >0:
12
+ font_a = font_a + (cnt * 2)
13
+ font_b = font_b + (cnt * 2)
14
+ #hh = hh-int(cnt/2)
15
+ hhh = hhh+int(cnt/2)
16
+ w,h = im.size
17
+ print (w)
18
+ print (h)
19
+ font_x = (w/2)
20
+ font_y = h-hhh
21
+ out = toi.process(im,txt,font_fac=font_a,font_x=font_x,font_y=hh,font_col="#000000",font_op=255)
22
+ out = toi.process(out,"Contact Card",font_fac=font_b,font_x=font_x,font_y=font_y,font_col="#000000",font_op=255)
23
+
24
+ return out
25
+ def custom_overlay(txt=None):
26
+ background = Image.open("background.jpg")
27
+ x,y = background.size
28
+ if x > y:
29
+ aa=y
30
+ if y > x:
31
+ aa=x
32
+ if x==y:
33
+ aa=x
34
+ out = f'{txt}'
35
+ print (f'txt {out}')
36
+ qrm = qr.QRCode(box_size=10,error_correction=qr.constants.ERROR_CORRECT_H)
37
+ qrm.add_data(out)
38
+ qrm.make(fit=True)
39
+ img1 = qrm.make_image(fill_color=fill, back_color="white")
40
+ img1 = img1.resize((aa,aa))
41
+ img1.save("im2.png")
42
+
43
+ image_bgr = cv2.imread('im2.png')
44
+
45
+ h, w, c = image_bgr.shape
46
+ image_bgra = np.concatenate([image_bgr, np.full((h, w, 1), 255, dtype=np.uint8)], axis=-1)
47
+ white = np.all(image_bgr == [255, 255, 255], axis=-1)
48
+ image_bgra[white, -1] = 0
49
+ cv2.imwrite('result.png', image_bgra)
50
+
51
+
52
+ over_im = Image.open("result.png")
53
+ background.paste(over_im, (0, 0), over_im)
54
+ background.save("out_im.png")
55
+ return "out_im.png"