Search code examples
pythonpython-imaging-library

TypeError: color must be int or single-element tuple


Here is the error encountered:

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()

The error occurs in ImageDraw.Draw for the stroke_fill parameter.

How can I fix this?


Solution

  • 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 an int or a single tuple.