Spaces:
Runtime error
Runtime error
File size: 1,681 Bytes
913b5c9 5cf66dd 913b5c9 b109b82 913b5c9 b109b82 913b5c9 |
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 57 58 59 60 61 62 63 |
import cv2
from PIL import Image
def textover(im,txt):
inp=2
hh=1
hhh=45
cnt = len(inp)
font_a = 30
font_b = 40
if cnt >0:
font_a = font_a + (cnt * 2)
font_b = font_b + (cnt * 2)
#hh = hh-int(cnt/2)
hhh = hhh+int(cnt/2)
w,h = im.size
print (w)
print (h)
font_x = (w/2)
font_y = h-hhh
out = toi.process(im,txt,font_fac=font_a,font_x=font_x,font_y=hh,font_col="#000000",font_op=255)
out = toi.process(out,"Contact Card",font_fac=font_b,font_x=font_x,font_y=font_y,font_col="#000000",font_op=255)
return out
def background_image():
img_b = np.zeros([512,512,1],dtype=np.uint8)
img_b.fill(255)
img_b.save("background.png")
def custom_overlay(txt=None):
background_image()
background = Image.open("background.png")
x,y = background.size
if x > y:
aa=y
if y > x:
aa=x
if x==y:
aa=x
out = f'{txt}'
print (f'txt {out}')
qrm = qr.QRCode(box_size=10,error_correction=qr.constants.ERROR_CORRECT_H)
qrm.add_data(out)
qrm.make(fit=True)
img1 = qrm.make_image(fill_color=fill, back_color="white")
img1 = img1.resize((aa,aa))
img1.save("im2.png")
image_bgr = cv2.imread('im2.png')
h, w, c = image_bgr.shape
image_bgra = np.concatenate([image_bgr, np.full((h, w, 1), 255, dtype=np.uint8)], axis=-1)
white = np.all(image_bgr == [255, 255, 255], axis=-1)
image_bgra[white, -1] = 0
cv2.imwrite('result.png', image_bgra)
over_im = Image.open("result.png")
background.paste(over_im, (0, 0), over_im)
background.save("out_im.png")
return "out_im.png" |