Search code examples
python-2.7python-imaging-libraryspecial-characters

Specal characters drawn weird to image using PY2.7 and Pillow


I'm trying to add text to an image using Pillow and the special Danish characters doesn't appear right.

I thought that it might be a font-problem since I read somewhere that it could be an issue but even when I specify a font I know is capable of showing the letters, they don't appear.

message="I want to add letters like ø and å"
image = Image.open('image.png')
draw = ImageDraw.Draw(image)
font_name = ImageFont.truetype('C:/Windows/Fonts/micross.ttf', size=20)
draw.text((155,165),message, fill=color, font=font_name)
image.show()

Now, the letters are super weird and, as an example, the letter å becomes "Ã,". Anything obvious I'm missing?


Solution

  • Python 2 uses ASCII encoding by default. Either switch to python3 or add u before the string:

    u"I want to add letters like ø and å"