0

I'm making a project were i make a video out of reddit post, part of it is getting a paragraph and adding a background image to it, i found out I could do it with pillow but my text overflows.

Code:

from PIL import Image , ImageDraw, ImageFont

text = "Some background: my friend lost her father and her two older sisters in a tragic car accident 7 years ago. " \
       "I was her shoulder to cry on. She became attached to me as a second sister " \
       "and grew closer to her only living sibling (her brother)."

new = Image.new('RGB', (1000, 1000), color=(3, 252, 232))
d = ImageDraw.Draw(new)
fnt = ImageFont.truetype("comicbd.ttf", 25)
d.text((0, 0), text, font=fnt, fill=(255, 255, 255))
new.show('img.jpg')

image of overflow: 1

David Scholz
  • 8,421
  • 12
  • 19
  • 34
  • Does this answer your question? [How to add text in a "textbox" to an image?](/q/67760340/90527) – outis Aug 21 '22 at 01:45
  • ... [PIL - draw multiline text on image](/q/7698231/90527), [Wrap text in PIL](/q/8257147/90527), [Break long drawn text to multiple lines with Pillow](/q/58041361/90527) – outis Aug 21 '22 at 01:59

1 Answers1

0

I think textwrap is builtin and can be used like

textwrap.wrap(str, len)

Atleast when I tried this using moviepy this was my easiest solution

Anthony L
  • 112
  • 6