David Parks
David Parks

Reputation: 32071

PIL Internal Exception: {TypeError}getsize() takes exactly 1 argument (3 given)

I get the exception referenced in the title using this code:

from PIL import Image, ImageDraw, ImageFont
img = Image.open('test_fixtures/image00161.jpg')
draw = ImageDraw.Draw(img)
font = ImageFont.load_default().font
draw.multiline_text((20,20), 'some text', 'white', font)

Here is the full stack trace:

Error
Traceback (most recent call last):
  File "/home/davidparks21/opt/anaconda3/envs/xevo/lib/python2.7/unittest/case.py", line 329, in run
    testMethod()
  File "/home/davidparks21/ws/git/src/common/ml/scripts/FitnetsFAN/xf_plot_landmarks_test.py", line 18, in test_plt_landmarks_on_image
    self.ground_truth_landmarks, self.ground_truth_landmarks + 7)
  File "/home/davidparks21/ws/git/src/common/ml/scripts/FitnetsFAN/xf_plot_landmarks.py", line 63, in plt_landmarks_on_image
    draw.multiline_text((20,20), legends, 'white', font)
  File "/home/davidparks21/opt/anaconda3/envs/xevo/lib/python2.7/site-packages/PIL/ImageDraw.py", line 234, in multiline_text
    line_spacing = self.textsize('A', font=font)[1] + spacing
  File "/home/davidparks21/opt/anaconda3/envs/xevo/lib/python2.7/site-packages/PIL/ImageDraw.py", line 263, in textsize
    return font.getsize(text, direction, features)
TypeError: getsize() takes exactly 1 argument (3 given)

When I look at line 263 of ImageDraw.py the code is:

return font.getsize(text, direction, features)

This leads me to one of three possible conclusions:

Anyone want to venture a guess as to which it is? Or propose a new possibility?

FYI:

PIL.VERSION
'1.1.7'
PIL.PILLOW_VERSION
'5.0.0'

Upvotes: 2

Views: 419

Answers (1)

Tarun Lalwani
Tarun Lalwani

Reputation: 146510

Change below

font = ImageFont.load_default().font

to

font = ImageFont.load_default()

And it should work

Upvotes: 2

Related Questions