python PIL图像绘制

2024-09-30 02:23:27 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的代码:

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'
 

请帮我解决这个错误


Tags: 代码textinimageinputpiltype错误

热门问题