Update video.py
Browse files
video.py
CHANGED
|
@@ -15,6 +15,7 @@ def create_text_image(text,id,image_olst, image_size=(1280, 720), bg_color="whit
|
|
| 15 |
draw = ImageDraw.Draw(image)
|
| 16 |
|
| 17 |
font_path = "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf"
|
|
|
|
| 18 |
max_font_size = 65
|
| 19 |
min_font_size = 10
|
| 20 |
|
|
@@ -34,10 +35,14 @@ def create_text_image(text,id,image_olst, image_size=(1280, 720), bg_color="whit
|
|
| 34 |
words = raw_line.split()
|
| 35 |
current_line = ""
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
for word in words:
|
| 38 |
test_line = f"{current_line} {word}" if current_line else word
|
| 39 |
w, _ = get_text_size(test_line, font)
|
| 40 |
-
if w <=
|
| 41 |
current_line = test_line
|
| 42 |
else:
|
| 43 |
lines.append(current_line)
|
|
@@ -51,11 +56,18 @@ def create_text_image(text,id,image_olst, image_size=(1280, 720), bg_color="whit
|
|
| 51 |
best_lines = lines
|
| 52 |
break
|
| 53 |
|
|
|
|
|
|
|
|
|
|
| 54 |
y = (image_size[1] - total_height) // 2
|
| 55 |
for line in best_lines:
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
y += h + 23
|
| 60 |
image_name="slide"+str(id)+".png"
|
| 61 |
image_olst.append(image_name)
|
|
|
|
| 15 |
draw = ImageDraw.Draw(image)
|
| 16 |
|
| 17 |
font_path = "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf"
|
| 18 |
+
bold_font_path = "/usr/share/fonts/truetype/liberation/LiberationSans-Bold.ttf"
|
| 19 |
max_font_size = 65
|
| 20 |
min_font_size = 10
|
| 21 |
|
|
|
|
| 35 |
words = raw_line.split()
|
| 36 |
current_line = ""
|
| 37 |
|
| 38 |
+
left_padding = 80
|
| 39 |
+
right_padding = 80
|
| 40 |
+
max_text_width = image_size[0] - left_padding - right_padding
|
| 41 |
+
|
| 42 |
for word in words:
|
| 43 |
test_line = f"{current_line} {word}" if current_line else word
|
| 44 |
w, _ = get_text_size(test_line, font)
|
| 45 |
+
if w <= max_text_width:
|
| 46 |
current_line = test_line
|
| 47 |
else:
|
| 48 |
lines.append(current_line)
|
|
|
|
| 56 |
best_lines = lines
|
| 57 |
break
|
| 58 |
|
| 59 |
+
heading_color = "#0033cc" # Deep attractive blue
|
| 60 |
+
normal_color = text_color # Usually black
|
| 61 |
+
|
| 62 |
y = (image_size[1] - total_height) // 2
|
| 63 |
for line in best_lines:
|
| 64 |
+
is_heading = line.strip().endswith("?") or line.strip().endswith(":")
|
| 65 |
+
font_to_use = ImageFont.truetype(bold_font_path, best_font.size) if is_heading else best_font
|
| 66 |
+
color_to_use = heading_color if is_heading else normal_color
|
| 67 |
+
|
| 68 |
+
w, h = get_text_size(line, font_to_use)
|
| 69 |
+
x = 80 # Left padding
|
| 70 |
+
draw.text((x, y), line, font=font_to_use, fill=color_to_use)
|
| 71 |
y += h + 23
|
| 72 |
image_name="slide"+str(id)+".png"
|
| 73 |
image_olst.append(image_name)
|