import cv2
from PIL import ImageFont, ImageDraw, Image
import numpy as np
bk_img = cv2.imread("share.png")
# 设置需要显示的字体
fontpath = "/Users/ps/projects/hymm/egret/trade/simsun.ttc"
font = ImageFont.truetype(fontpath, 15 * 2,)
img_pil = Image.fromarray(bk_img)
draw = ImageDraw.Draw(img_pil)
# 绘制文字信息
draw.text((35 * 2, 78 * 2), "买家信息", font=font, fill=(255, 255, 255))
draw.text((100, 350), "地方a测试\n你好啊测试", font=font, fill=(255, 255, 255))
bk_img = np.array(img_pil)
# cv2.imshow("add_text",bk_img)
# cv2.waitKey()
cv2.imwrite("add_text.jpg", bk_img)