一张照片命名成千个不同的名称图片,如何处理,并且名称并添加到图片中,
例如,资料就一张照片,我就批量弄成1到100张照片,并且图片名称是1.2.3,100.并且图片中央有名称的文字logo 12.3.100
python 在图片中添加文字,并保存图片
参考
https://www.jb51.net/article/175078.htm
from PIL import Image,ImageDraw,ImageFont
path = 'xxx.png' #打开的图片
for i in range(1,101):
img = Image.open(path)
w,h = img.size
x = int(w / 2)
y = int(h / 2)
draw = ImageDraw.Draw(img)
string = f"logo {i}"
font = ImageFont.truetype(r'C:\Windows\Fonts\consola.ttf', 20)
draw.text((x,y),string,fill='red',font=font,align="center")
img.save(f"{i}.png")
# img.show()
print(f"生成: {i}.png")
如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!