图片转字符
'''
Description: henggao_note
version: v1.0.0
Date: 2022-03-17 09:50:31
LastEditors: henggao
LastEditTime: 2022-03-17 10:05:22
'''
from PIL import Image, ImageDraw, ImageFont
font_size = 10
text = "恒高"
img_path = "person.jpg"
img_raw = Image.open(img_path)
img_array = img_raw.load()
img_new = Image.new("RGB", img_raw.size, (0, 0, 0))
draw = ImageDraw.Draw(img_new)
font = ImageFont.truetype('C:\Windows\Fonts\FZSTK.TTF', font_size)
def character_generator(text):
while True:
for i in range(len(text)):
yield text[i]
ch_gen = character_generator(text)
for y in range(0, img_raw.size[1], font_size):
for x in range(0, img_raw.size[0], font_size):
draw.text((x, y), next(ch_gen), font=font,
fill=img_array[x, y], direction=None)
img_new.convert('RGB').save("222.jpg")
视频转字符
安装pygame
pip install pygame
ModuleNotFoundError: No module named '_curses'
pip install windows-curses
pip install matplotlib