ImageFont's getsize() does not get correct text size?

后端 未结 3 718
面向向阳花
面向向阳花 2021-01-05 20:35

I use the following two methods to to generate text preview image for a .ttf font file

PIL method:

def make_preview(text, fontfile,          


        
3条回答
  •  猫巷女王i
    2021-01-05 20:45

    Not a programming solution, but when I regenerate your problem, its only happens on your fonts (other fonts like Arial is no problem at all), so I have fixed your font files (by changing ascent/decent metrics). you can download here,

    And sorry about Hanford Script Font, its not perfect as you see, height seems ok, but left side is not get drawed, its out of my understanding.

    UPDATE: Regarding Hanford Font, Here is a work around, pass extra space in text like " Handford Script", and then crop the extra space in image like img=img.crop(img.getbbox())

    alt text http://img64.imageshack.us/img64/1903/hanfordfontworkaround.jpg

    UPDATE2:I had to pass color=(255,255,255) in Image.New to get Black Text on White background

    img = Image.new('RGBA', (text_width, text_height),color=(255,255,255))
    

提交回复
热议问题