W, H = (1285,720)
text = "Hello world"
img = Image.open("img.png")
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("/usr/share/fonts/MyriadProCondBold.ttf", 90)
w, h = draw.textsize(text.encode('utf-8'), font=font)
draw.text(((W-w)/2,520),text,(255,255,255),font=font)
w, h = draw.textsize(text.encode('utf-8'), font=font)
File "/usr/lib/python3.5/site-packages/PIL/ImageDraw.py", line 273, in textsize
return font.getsize(text)
File "/usr/lib/python3.5/site-packages/PIL/ImageFont.py", line 141, in getsize
size, offset = self.font.getsize(text)
TypeError: expected string
Just as an explanation of what's happening - you are passing in bytes when it 'expected string'. If you change text.encode('utf-8') to just text, you should find that the code runs without a problem.
Thanks for the thumbs up response. If you feel like that resolves your situation, please close this issue.
@radarhere thanks for the help. You've been very much helped me. Issue has been resolved!
Most helpful comment
Just as an explanation of what's happening - you are passing in bytes when it 'expected string'. If you change
text.encode('utf-8')to justtext, you should find that the code runs without a problem.