|
- from PIL import ImageFont
- from PIL import Image
- import os
- from PIL import ImageDraw
- name = []
- path = []
- for lujing,wenjianjia,wenjian in os.walk('D:\练习Python\新建文件夹'):
- for file in os.scandir(lujing):
- #print(file.name)
- name.append(file.name)
- #print(lujing)
- j = lujing + '\\'+file.name
- #print(j)
- path.append(j)
- zidian = dict(zip(name,path))
- #print(zidian)
- for name,path in zidian.items():
- imageFile = path
- img = Image.open(imageFile)
- font = ImageFont.truetype("C:\Windows\Fonts\STZHONGS.TTF", 40)
- word = name
- width = img.width
- height = img.height
- #print(width,height)
- position = (100, height*0.6)
- color = (0,0,0)
- draw = ImageDraw.Draw(img)
- draw.text(position, word, color, font=font)
- # 保存图片
- img.save(imageFile)
复制代码
|
|