且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在tkinter中的图像顶部添加文本

更新时间:2023-12-05 16:19:22

您需要先打开/加载图像,如下所示:

You need to open/load the image first... like this:

#!/usr/local/bin/python3

import numpy as np
from PIL import Image, ImageDraw, ImageFont

# Open input image
im = Image.open('image.png').convert('RGB')

# Get a drawing context
draw = ImageDraw.Draw(im)

pixellat=ImageFont.truetype("/Library/Fonts/Apple Chancery.ttf",48)
draw.text((80, 40),"This is a test",(255,255,255),font=pixellat)

# Save
im.save('result.png')