Skip to content

Unable to render text with emojis #1774

@novadev94

Description

@novadev94

I want to use Pillow to render text with emojis, to get it easy, I've used a font named Symbola.

# -*- coding: utf-8 -*-
from PIL import Image, ImageFont, ImageDraw
text = u'A😞B'
image = Image.new('RGB', (100, 100), 'white')
font = ImageFont.truetype('Symbola.ttf', size=36, encoding='unic')
draw = ImageDraw.Draw(image)
draw.text((0, 0), text, (0, 0, 0), font=font)
image.show()

But seem like it doesn't succeed
image

When I switched to Apple Color Emoji, I have another problem on line

draw.text((0, 0), text, (0, 0, 0), font=font)

# Traceback (most recent call last):
#   File "hello.py", line 13, in <module>
#     draw.text((0, 0), text, (0, 0, 0), font=font)
#   File "/work/emoji/venv/lib/python2.7/site-packages/PIL/ImageDraw.py", line 280, in text
#     mask, offset = font.getmask2(text, self.fontmode)
#   File "/work/emoji/venv/lib/python2.7/site-packages/PIL/ImageFont.py", line 163, in getmask2
#     size, offset = self.font.getsize(text)
# IOError: invalid size handle

So what should I do to be able to render emojis?


May related to #1422

Also someone has reported a problem about ColorFont support in FreeType (this is a Chinese blog) http://www.cnblogs.com/palance/p/4809872.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions