compact.py 305 字节
Newer Older
1 2
import PIL

3
def imagedraw_textsize_c(draw, text, font=None):
4
    if int(PIL.__version__.split('.')[0]) < 10:
5
        tw, th = draw.textsize(text, font=font)
6
    else:
7
        left, top, right, bottom = draw.textbbox((0, 0), text, font=font)
8 9 10
        tw, th = right - left, bottom - top

    return tw, th
11