fonts clipping with PIL

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

    I couldn't solve this problem for some fonts using the approaches mentioned so far, so I ended up using aggdraw as a transparent replacement for PIL's text drawig methods.

    Your code rewritten to aggdraw would look like:

    import Image
    import aggdraw
    
    im = Image.new("RGBA", (200, 200), 'white')
    draw = aggdraw.Draw(im)
    
    # note that the color is specified in the font constructor in aggdraw
    font = aggdraw.Font((0,0,0), "VeraSe.ttf", size=12, opacity=255)
    
    draw.text((1, 1), " %s: " % "ggjyfFwe__", font) # no color here
    draw.text((1, 30), " %s" % 15, font)
    
    draw.flush() # don't forget this to update the underlying PIL image!
    
    im.show()
    

提交回复
热议问题