Draw bold/italic text with PIL?

后端 未结 4 1973
悲&欢浪女
悲&欢浪女 2021-01-07 18:37

How to draw bold/italic text with PIL? ImageFont.truetype(file, size) has an option to specify font size only.

4条回答
  •  终归单人心
    2021-01-07 19:05

    A rather hacky solution to make a font bold if (for whatever reason) you don't have a separate bold version of the font is to print the same text several times with a slight offset.

    andaleMono = ImageFont.truetype(ANDALE_MONO_PATH,16)
    text = "hello world"
    mainOffset = (50,50)
    xoff, yoff = mainOffset
    draw.text(mainOffset,text,font=andaleMono,fill='black')
    draw.text((xoff+1,yoff+1),text,font=andaleMono,fill='black')
    draw.text((xoff-1,yoff-1),text,font=andaleMono,fill='black')
    

提交回复
热议问题