Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -39,7 +39,7 @@ def get_uploaded_logo():
|
|
39 |
|
40 |
# Create image slides from text chunks with emojis and shapes
|
41 |
def create_slides(text, duration, output_folder, max_lines=6):
|
42 |
-
font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans
|
43 |
font = ImageFont.truetype(font_path, 48)
|
44 |
logo_path = get_uploaded_logo()
|
45 |
|
@@ -62,16 +62,14 @@ def create_slides(text, duration, output_folder, max_lines=6):
|
|
62 |
|
63 |
# Text
|
64 |
lines = slide_text.split("\n")
|
65 |
-
|
66 |
-
total_height = sum([b[3] - b[1] for b in line_sizes]) + (len(lines)-1)*20
|
67 |
y = max((720 - total_height) // 2, 20)
|
68 |
|
69 |
-
for line
|
70 |
-
|
71 |
-
|
72 |
-
decorated = random.choice(emoji_pool) + " " + line + " " + random.choice(emoji_pool)
|
73 |
draw.text(((1280 - w) // 2, y), decorated, font=font, fill="white")
|
74 |
-
y +=
|
75 |
|
76 |
# Logo
|
77 |
logo = Image.open(logo_path).convert("RGBA")
|
|
|
39 |
|
40 |
# Create image slides from text chunks with emojis and shapes
|
41 |
def create_slides(text, duration, output_folder, max_lines=6):
|
42 |
+
font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf" # more emoji-compatible
|
43 |
font = ImageFont.truetype(font_path, 48)
|
44 |
logo_path = get_uploaded_logo()
|
45 |
|
|
|
62 |
|
63 |
# Text
|
64 |
lines = slide_text.split("\n")
|
65 |
+
total_height = sum([font.getbbox(line)[3] - font.getbbox(line)[1] for line in lines]) + (len(lines)-1)*20
|
|
|
66 |
y = max((720 - total_height) // 2, 20)
|
67 |
|
68 |
+
for line in lines:
|
69 |
+
decorated = f"{random.choice(emoji_pool)} {line} {random.choice(emoji_pool)}"
|
70 |
+
w = font.getbbox(decorated)[2] - font.getbbox(decorated)[0]
|
|
|
71 |
draw.text(((1280 - w) // 2, y), decorated, font=font, fill="white")
|
72 |
+
y += font.getbbox(decorated)[3] - font.getbbox(decorated)[1] + 20
|
73 |
|
74 |
# Logo
|
75 |
logo = Image.open(logo_path).convert("RGBA")
|