Wrap text in PIL

前端 未结 5 939
太阳男子
太阳男子 2020-12-30 03:40

I\'m using PIL to draw text on an image. How would I wrap a string of text. This is my code:

text = \"Lorem ipsum dolor sit amet, consectetur adipisicing eli         


        
5条回答
  •  一个人的身影
    2020-12-30 04:34

    The accepted solution wraps text basing on the fixed limit of 40 characters per line, not taking into account the box width (in pixels) nor font size. This may easily lead to underfill or overfill.

    Here is a better solution - a simple code snippet to wrap text taking into account font-based width measurement: https://gist.github.com/turicas/1455973

提交回复
热议问题