RohitCSharp commited on
Commit
b7fb1f9
·
verified ·
1 Parent(s): da2d8c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -8
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-Bold.ttf"
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
- line_sizes = [draw.textbbox((0, 0), line, font=font) for line in lines]
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, bbox in zip(lines, line_sizes):
70
- w = bbox[2] - bbox[0]
71
- h = bbox[3] - bbox[1]
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 += h + 20
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")