Python PIL每个字符宽度相同

时间:2014-07-13 16:38:12

标签: python-2.7 python-imaging-library

我试图通过使用带有python的PIL包将一些文本绘制到图片上。有没有办法可以画出相同宽度的每个角色?

谢谢!

1 个答案:

答案 0 :(得分:1)

经过一段时间的考虑后,我得到了以下作品:

   for num, (text, color) in enumerate(wrap):
        if num==12:
            current_h=0
        if num<12:
            sw=0
        else:
            sw=MAX_W/2
        w,h=d.textsize(text.decode('gbk'), font=f)
        print list(text)
        for char in list(text):
            d.text((10+sw, current_h), char.decode('gbk'), font = f, fill = color)
            sw+=10
        current_h+=h
        print w,h