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)