RohitCSharp commited on
Commit
d9287c4
·
verified ·
1 Parent(s): eefc307

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -37,13 +37,23 @@ def get_uploaded_logo():
37
  dst.write(src.read())
38
  return logo_path
39
 
40
- # Create image slides from text chunks with pasted emoji icons
41
- emoji_img_path = "/home/user/app/emoji_fire.png" # pre-uploaded emoji icon (e.g., fire)
42
-
 
 
 
 
 
 
 
 
 
43
  def create_slides(text, duration, output_folder, max_lines=6):
44
  font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"
45
  font = ImageFont.truetype(font_path, 48)
46
  logo_path = get_uploaded_logo()
 
47
 
48
  chunks = textwrap.wrap(text, width=36)
49
  slides = ["\n".join(chunks[i:i+max_lines]) for i in range(0, len(chunks), max_lines)]
@@ -54,24 +64,18 @@ def create_slides(text, duration, output_folder, max_lines=6):
54
  img = Image.new("RGB", (1280, 720), color=(20, 30, 60))
55
  draw = ImageDraw.Draw(img)
56
 
57
- # Draw text
58
  lines = slide_text.split("\n")
59
  total_height = sum([font.getbbox(line)[3] - font.getbbox(line)[1] for line in lines]) + (len(lines)-1)*20
60
  y = max((720 - total_height) // 2, 20)
61
 
62
- emoji_img = Image.open(emoji_img_path).resize((48, 48)).convert("RGBA")
63
-
64
  for line in lines:
65
  w = font.getbbox(line)[2] - font.getbbox(line)[0]
66
  text_x = (1280 - w) // 2
67
  draw.text((text_x, y), line, font=font, fill="white")
68
- # Paste emoji left
69
  img.paste(emoji_img, (text_x - 60, y), emoji_img)
70
- # Paste emoji right
71
  img.paste(emoji_img, (text_x + w + 12, y), emoji_img)
72
  y += font.getbbox(line)[3] - font.getbbox(line)[1] + 20
73
 
74
- # Paste logo
75
  logo = Image.open(logo_path).convert("RGBA")
76
  logo_width = min(180, int(0.15 * img.width))
77
  logo_height = int(logo.size[1] * (logo_width / logo.size[0]))
 
37
  dst.write(src.read())
38
  return logo_path
39
 
40
+ # Get or generate fallback emoji image
41
+ def get_emoji_image():
42
+ emoji_path = "/home/user/app/emoji_fire.png"
43
+ if os.path.exists(emoji_path):
44
+ return Image.open(emoji_path).resize((48, 48)).convert("RGBA")
45
+ else:
46
+ fallback = Image.new("RGBA", (48, 48), (255, 0, 0, 0))
47
+ draw = ImageDraw.Draw(fallback)
48
+ draw.ellipse((4, 4, 44, 44), fill=(255, 69, 0, 255))
49
+ return fallback
50
+
51
+ # Create image slides from text chunks with emojis and logo
52
  def create_slides(text, duration, output_folder, max_lines=6):
53
  font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"
54
  font = ImageFont.truetype(font_path, 48)
55
  logo_path = get_uploaded_logo()
56
+ emoji_img = get_emoji_image()
57
 
58
  chunks = textwrap.wrap(text, width=36)
59
  slides = ["\n".join(chunks[i:i+max_lines]) for i in range(0, len(chunks), max_lines)]
 
64
  img = Image.new("RGB", (1280, 720), color=(20, 30, 60))
65
  draw = ImageDraw.Draw(img)
66
 
 
67
  lines = slide_text.split("\n")
68
  total_height = sum([font.getbbox(line)[3] - font.getbbox(line)[1] for line in lines]) + (len(lines)-1)*20
69
  y = max((720 - total_height) // 2, 20)
70
 
 
 
71
  for line in lines:
72
  w = font.getbbox(line)[2] - font.getbbox(line)[0]
73
  text_x = (1280 - w) // 2
74
  draw.text((text_x, y), line, font=font, fill="white")
 
75
  img.paste(emoji_img, (text_x - 60, y), emoji_img)
 
76
  img.paste(emoji_img, (text_x + w + 12, y), emoji_img)
77
  y += font.getbbox(line)[3] - font.getbbox(line)[1] + 20
78
 
 
79
  logo = Image.open(logo_path).convert("RGBA")
80
  logo_width = min(180, int(0.15 * img.width))
81
  logo_height = int(logo.size[1] * (logo_width / logo.size[0]))