@@ -29,20 +29,33 @@ def new_background(size, color, bs=20, boxes=50):
29
29
return im
30
30
31
31
32
+ def add_text (im , xy , text , min_lines , line_height , font , color ):
33
+ x , y = xy
34
+ d = ImageDraw .Draw (im )
35
+ lines = text .splitlines ()
36
+ text_height = len (lines ) * line_height
37
+ min_text_height = min_lines * line_height
38
+ y = int (y * (im .height - text_height ) / (im .height - min_text_height ))
39
+ for line in text .splitlines ():
40
+ d .text ((x , y ), line , fill = color , font = font )
41
+ y += line_height
42
+ return d
43
+
44
+
32
45
def mk_welcome_image (info ):
33
46
font = ImageFont .truetype (ttf_path , 20 )
34
47
im = new_background (welcome_size , info ['_color' ])
35
- d = ImageDraw .Draw (im )
36
- d .text ((20 , 100 ), info ['name' ], fill = white , font = font )
37
- d .text ((20 , 130 ), info ['version' ], fill = white , font = font )
48
+ text = '\n ' .join ([info ['welcome_image_text' ], info ['version' ]])
49
+ add_text (im , (20 , 100 ), text , 2 , 30 , font , white )
38
50
return im
39
51
40
52
41
53
def mk_header_image (info ):
42
54
font = ImageFont .truetype (ttf_path , 20 )
43
55
im = Image .new ('RGB' , header_size , color = white )
44
- d = ImageDraw .Draw (im )
45
- d .text ((20 , 15 ), info ['name' ], fill = info ['_color' ], font = font )
56
+ text = info ['header_image_text' ]
57
+ color = info ['_color' ]
58
+ add_text (im , (20 , 15 ), text , 1 , 20 , font , color )
46
59
return im
47
60
48
61
0 commit comments