中文"/>
Python在PIL和matplotlib图片上输出中文
一、matplotlib
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = ['sans-serif']
plt.rcParams['font.sans-serif'] = ['SimHei']
img = plt.imread("src_img/1698739560094.jpeg")
# plt.text(x, y, str, fontdict=None, withdash=False, **kwargs)
# x,y:位置(position)
# str:该position需要展示的值
# fontdict:字体
# withdash:宽度
plt.text(100,100,"我是")
plt.imshow(img)
plt.show()
二、PIL
import cv2
from PIL import Image, ImageDraw, ImageFontimg = cv2.imread("src_img/1698739560094.jpeg")
img_c = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
draw = ImageDraw.Draw(img_c)
font = ImageFont.truetype("simhei.ttf", 20) # 设置字体 (参数字体,文字大小)
draw.text((100, 200), "哈哈哈", (255, 0, 0), font=font) # 参数(字的位置,字的内容,颜色,字体)
img_c.show()
更多推荐
Python在PIL和matplotlib图片上输出中文
发布评论