使用wand您将使用wand.drawing.Drawing.get_font_metrics
which 将返回FontMetrics
类的实例。
例子
from wand.image import Image
from wand.drawing import Drawing
with Image(filename='wizard:') as img:
with Drawing() as context:
context.font_family = 'monospace'
context.font_size = 25
metrics = context.get_font_metrics(img,
"How BIG am I?",
multiline=False)
print(metrics)
#=> FontMetrics(character_width=25.0,
# character_height=25.0,
# ascender=23.0,
# descender=-5.0,
# text_width=170.0,
# text_height=29.0,
# maximum_horizontal_advance=50.0,
# x1=0.0,
# y1=0.0,
# x2=19.21875,
# y2=18.0,
# x=170.0,
# y=0.0)