andreinigo commited on
Commit
91bb5aa
·
1 Parent(s): 437e10c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -43,9 +43,12 @@ def generate_caption(image):
43
  font_size = int(max_width / (len(meme_text) / 2))
44
  font = ImageFont.truetype("impact.ttf", font_size)
45
 
 
 
 
46
  # Wrap the text to fit within the image width and have a maximum of 2 lines
47
- wrapped_text = textwrap.fill(meme_text, width=int(max_width / font.getsize("A")[0]))
48
- text_lines = wrapped_text.split('\n')
49
 
50
  y = 10
51
  for line in text_lines:
 
43
  font_size = int(max_width / (len(meme_text) / 2))
44
  font = ImageFont.truetype("impact.ttf", font_size)
45
 
46
+ # Calculate the width for text wrap
47
+ wrap_width = len(meme_text) // 2
48
+
49
  # Wrap the text to fit within the image width and have a maximum of 2 lines
50
+ wrapped_text = textwrap.wrap(meme_text, width=wrap_width)
51
+ text_lines = wrapped_text
52
 
53
  y = 10
54
  for line in text_lines: