Reputation: 60
This is my code:
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()
But when I run this code it shows this error,
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'
Please help me to solve this error.
Upvotes: 0
Views: 2502
Reputation: 595
From Pillow Documentation:
You have to do
font = ImageFont.truetype("C:\\Windows\\Fonts\\Fira Code\\FiraCode-Regular.ttf", 100)
.
The text module expects an ImageFont object, not a string.
Upvotes: 0