fonts clipping with PIL

后端 未结 5 2101
面向向阳花
面向向阳花 2020-12-19 09:40

This image was created with PIL. See how the g\'s and the y\'s are cut off in this image? How can I prevent this?

http://img109.imageshack.us/img109/8874/screenshote

5条回答
  •  独厮守ぢ
    2020-12-19 10:36

    My suggestion is, before you create the image object, to get the required size for the text.

    This is done using font.getsize("text") (documentation).

    In a image generating script I made, I first found the maximum height of one line of text, by calling the equvalient of font.getsize("Åj") (If you only need US-ASCII, you could find the height of "Aj" instead). Then I calculated the required image height and line offsets, including margins and line-spacing.

提交回复
热议问题