1

I want to write multiline text to an image and highlight some parts of it with green or red (to produce a diff and show the edits in a block of text, in an image). The idea would be to input a text (with some way to say which parts should have which formatting), an image width and height, and to get the image as an output.

I can envision how I can do this with PIL's ImageDraw.Draw().text() and .textsize() to calculate when to go to a new line as well as the sizes and positions for each .rectangle() (which would be the highlighting), but it all seems fairly tiresome, and I can't be the first person who needs to do this. Is there some better package to do this?

François M.
  • 4,027
  • 11
  • 30
  • 81
  • 1
    Not sure this will help, but check this out: https://stackoverflow.com/questions/5414639/python-imaging-library-text-rendering – Gulzar May 21 '20 at 18:16

0 Answers0