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?