RohitCSharp commited on
Commit
473c60d
·
verified ·
1 Parent(s): d3a1880

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -39,10 +39,10 @@ def get_uploaded_logo():
39
  # Create image slides from text chunks
40
  def create_slides(text, duration, output_folder, max_lines=6):
41
  font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"
42
- font = ImageFont.truetype(font_path, 64)
43
  logo_path = get_uploaded_logo()
44
 
45
- chunks = textwrap.wrap(text, width=40)
46
  slides = ["\n".join(chunks[i:i+max_lines]) for i in range(0, len(chunks), max_lines)]
47
  per_slide_time = duration / len(slides)
48
  slide_paths = []
@@ -52,18 +52,21 @@ def create_slides(text, duration, output_folder, max_lines=6):
52
  draw = ImageDraw.Draw(img)
53
 
54
  lines = slide_text.split("\n")
55
- total_height = sum([draw.textbbox((0, 0), line, font=font)[3] - draw.textbbox((0, 0), line, font=font)[1] for line in lines]) + (len(lines)-1)*10
56
- y = (720 - total_height) // 2
 
57
 
58
- for line in lines:
59
- bbox = draw.textbbox((0, 0), line, font=font)
60
  w = bbox[2] - bbox[0]
61
  h = bbox[3] - bbox[1]
62
  draw.text(((1280 - w) // 2, y), line, font=font, fill="white")
63
- y += h + 10
64
 
65
- logo = Image.open(logo_path).convert("RGBA").resize((120, 120))
66
- img.paste(logo, (40, 40), logo)
 
 
 
67
 
68
  frame_path = os.path.join(output_folder, f"slide_{i}.png")
69
  img.save(frame_path)
 
39
  # Create image slides from text chunks
40
  def create_slides(text, duration, output_folder, max_lines=6):
41
  font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"
42
+ font = ImageFont.truetype(font_path, 48)
43
  logo_path = get_uploaded_logo()
44
 
45
+ chunks = textwrap.wrap(text, width=36)
46
  slides = ["\n".join(chunks[i:i+max_lines]) for i in range(0, len(chunks), max_lines)]
47
  per_slide_time = duration / len(slides)
48
  slide_paths = []
 
52
  draw = ImageDraw.Draw(img)
53
 
54
  lines = slide_text.split("\n")
55
+ line_sizes = [draw.textbbox((0, 0), line, font=font) for line in lines]
56
+ total_height = sum([b[3] - b[1] for b in line_sizes]) + (len(lines)-1)*20
57
+ y = max((720 - total_height) // 2, 20)
58
 
59
+ for line, bbox in zip(lines, line_sizes):
 
60
  w = bbox[2] - bbox[0]
61
  h = bbox[3] - bbox[1]
62
  draw.text(((1280 - w) // 2, y), line, font=font, fill="white")
63
+ y += h + 20
64
 
65
+ logo = Image.open(logo_path).convert("RGBA")
66
+ logo_width = min(180, int(0.15 * img.width))
67
+ logo_height = int(logo.size[1] * (logo_width / logo.size[0]))
68
+ logo = logo.resize((logo_width, logo_height))
69
+ img.paste(logo, (img.width - logo_width - 30, img.height - logo_height - 30), logo)
70
 
71
  frame_path = os.path.join(output_folder, f"slide_{i}.png")
72
  img.save(frame_path)