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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With