本程序会把图片增高,并且在上面加上文字。
from PIL import Image,ImageTk,ImageDraw,ImageFont
def add_name(im,name):
"""im:pillow图形对象,name:字符串,本函数会在图像上面增加名字"""
width,height = im.size
hat = Image.new("RGBA",size=(width,50))
fnt = ImageFont.truetype('simkai.ttf',22)
d = ImageDraw.Draw(hat)
d.multiline_text((width//2,0),name,font=fnt,fill=(0,0,255))
new = Image.new("RGBA",size=(width,50+height))
box = (0,0,width-1,49)
new.paste(hat,(0,0))
new.paste(im,(0,50))
return new
im = Image.open('印度经典电影.png')
im2 = add_name(im,'图片增高')
im2.save('test.png')
