TypeError: color must be int or single-element tuple

Question:

Here is the error encoutered:

TypeError: color must be int or single-element tuple

Here is the code I am running:

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont, ImageOps
label1 = "VIKRAM"
font = ImageFont.truetype('D:/vikram/pythonProject/fonts/BalloonCraft-9YBK7.ttf', 800)
line_height = sum(font.getmetrics())
fontimage1 = Image.new('L', (font.getsize(label1)[0], line_height))
ImageDraw.Draw(fontimage1).text((0,0),str(label1),stroke_width=10, stroke_fill=(0, 0, 0), fill=255, font=font)
fontimage1 = fontimage1.rotate(90, resample=Image.NEAREST, expand=True)
orig = Image.open('F:/desktop/Kitty/PSI Hello Kitty Theme Personalized Door Poster-1.png')
orig.paste((135, 255, 135), box=(2200, 1500), mask=fontimage1)
orig.show()

If you have any idea how to fix this, please I would be very grateful. Thanks in advance.

Asked By: Windy_2212

||

Answers:

I belive as you put the ‘L’ in Image.new your image will be gray scale, therefore you can’t specify a RGB tuple for stroke_fill because you only have black shades. As specified in the error message you have to use a int or a single tuple.

Answered By: aladeen57

I have a better way to deal with this error
any time when you have color or stroke_fill param, always use strings like ‘red’, ‘green’, ‘black’

for above code, have it this way

ImageDraw.Draw(fontimage1).text((0,0),str(label1),stroke_width=10, stroke_fill='black', fill=255, font=font)
Answered By: Prajot Kuvalekar
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.