html_and_vue/全员营销奖励.py

30 lines
949 B
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from PIL import Image, ImageDraw, ImageFont
def add_text(image, font_path, save_name):
# 打开图片
image = Image.open(r"D:\下载\员工奖励bg.png")
# 创建一个可编辑的图片副本
draw = ImageDraw.Draw(image)
# 设置要添加的文本
text = "手机银行"
# 选择字体和字号
font_path = r"C:\Users\Cori\OneDrive\Documents\WeChat Files\fumeng0108\FileStorage\File\2020-05\思源黑体7款\思源黑体7款\SourceHanSansCN-Bold.otf"
font = ImageFont.truetype(font_path, 36)
# 获取文本大小
text_width, text_height = draw.textsize(text, font)
# 计算文本的位置使其居中
image_width, image_height = image.size
text_x = (image_width - text_width) / 2
text_y = 19
# 在图片上添加文本
draw.text((text_x, text_y), text, font=font, fill="#AA1017")
# 保存修改后的图片
image.save(r"D:\下载\员工营销\1bg.png")