import cv2
import numpy as np
from PIL import ImageFont, Image, ImageDraw
def create_pic():
width = 256
height = 256
img = np.zeros([width, height, 3], dtype=np.uint8)
for i in range(width):
for j in range(height):
img[i, j, :] = [i % 256, j % 256, (i + j) % 256]
cv2.imwrite("image.jpg", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
def write_pic(number):
bk_img = cv2.imread("image.jpg")
fontpath = "font/simsun.ttc"
font = ImageFont.truetype(fontpath, 32)
img_pil = Image.fromarray(bk_img)
draw = ImageDraw.Draw(img_pil)
draw.text((0, 0), "想写什么写什么", font=font, fill=(255, 255, 255))
draw.text((0, 50), number, font=font, fill=(255, 255, 255))
bk_img = np.array(img_pil)
cv2.waitKey()
createName = number + ".jpg"
cv2.imwrite(createName, bk_img)
if __name__ == '__main__':
create_pic()
for i in range(1, 11):
write_pic('BB' + "_" + str(i))