Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PIL TypeError: text() has multiple values for argument 'font'

I have the function:

imagewidth = 250 
y_positions = [65.0, 85.0, 105.0, 125.0, 145.0, 165.0] 
numbers_to_show = [20, 30, 40, 50, 60, 70]

def draw_numbers(imagewidth, y_positions, numbers_to_show):
    counter = 0
    while counter < len(y_positions):
        numbers_to_show = str(numbers_to_show[counter])
        font = ImageFont.truetype("impact.ttf",20)
        img = Image.open("agepyramid.bmp")
        draw = ImageDraw.Draw(img)
        draw.text(20 , y_positions[counter],numbers_to_show,(0,0,0),font=font)
        draw = ImageDraw.Draw(img)
        img.save("agepyramid.bmp")
        counter = counter + 1

I think this function should give me a picture with the "numbers_to_show" at the "y_position" of the image, but it gives me this error:

draw.text(20 , y_positions[counter],numbers_to_show,(0,0,0),font=font)
TypeError: text() got multiple values for argument 'font'

What am I doing wrong?

like image 357
Sven Avatar asked Mar 17 '23 03:03

Sven


1 Answers

The 4th argument of Draw.text is font. You provide 2 values for font argument - (0, 0, 0) (by position) and font (by name), and this confuses the interpreter.

I guess you want

draw.text((20 , y_positions[counter]), numbers_to_show, (0, 0, 0), font=font)

where (0, 0, 0) is the value for fill argument.

like image 64
vaultah Avatar answered Mar 24 '23 05:03

vaultah