这是我的代码:
from PIL import Image, ImageDraw, ImageFont
image = Image.open('C:\\Users\\User\\Downloads\\marple.jpg')
input_text = 'Hey gys'
font = 'C:\\Windows\\Fonts\\Fira Code\\FiraCode-Regular.ttf'
size = 100
colour = [1,2,3]
for i in range(0,3):
colour[i] = int(input(f'Colour (RGB value {i + 1}) : '))
colour = tuple(colour)
type_text = ImageDraw.Draw(image)
type_text.text((0,0), input_text, font = font, fill = (255,0,0) )
image.show()
但是当我运行这段代码时,它显示了这个错误
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-
packages\PIL\ImageDraw.py", line 408, in draw_text
mask, offset = font.getmask2(
AttributeError: 'str' object has no attribute 'getmask2'
请帮我解决这个错误
从Pillow Documentation:
你必须这样做
font = ImageFont.truetype("C:\\Windows\\Fonts\\Fira Code\\FiraCode-Regular.ttf", 100)
。 文本模块需要一个ImageFont对象,而不是字符串相关问题 更多 >
编程相关推荐