fonts clipping with PIL

后端 未结 5 2088
面向向阳花
面向向阳花 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:20

    The "bug" still exists in 2012, with Ubuntu 11.10. Fontsize 11, 12, 13 and 15 clip the underscore completely.

    #!/usr/bin/env python
    """ demonstrates clipping of descenders for certain font sizes """
    import Image, ImageDraw, ImageFont
    fontPath = "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf"
    im = Image.new('L', (256, 256))
    ys=15
    for i in range(10,21):
        fh = ImageFont.truetype(fontPath, i)
        sometext="%dgt_}" % (i)
        ImageDraw.Draw(im).text((10, ys ),sometext , 254, fh)
        ys+=i+5
    im.show()
    

提交回复
热议问题