You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
316 B

11 months ago
from PIL import Image, ImageDraw, ImageFont
# 创建一个图像
image = Image.new("RGB", (100, 100), "white")
draw = ImageDraw.Draw(image)
# 加载默认字体
font = ImageFont.load_default()
# 要获取文本的大小
text = "Hello, World!"
text_size = draw.textsize(text, font)
print("Text size:", text_size)