使用PIL渲染表情符号 [英] Rendering Emoji with PIL

查看:312
本文介绍了使用PIL渲染表情符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用推文制作图像,但是其中一些包含 Emojis .我正在使用 PIL 渲染图像和 Symbola 字体.

I am trying to make images out of tweets, however some of them contain Emojis. I am using PIL to render my images and the Symbola font.

文本采用utf-8 Unicode编码,并且Symbola字体确实包含表情符号.这是该代码的简化版本:

The text is in unicode utf-8 encoding and the Symbola font does include the emojis. Here is an abridged version of the code:

from PIL import Image, ImageFont, ImageDraw
text = u"\U0001f300" #CYCLONE emoji
image = Image.new("RGBA", (100,100), (255,255,255))
font = ImageFont.truetype("Symbola.ttf", 60, encoding='unic')
draw = ImageDraw.Draw(image)
draw.text((0,0), text, (0,0,0), font=font)
image.save("Test.png")
image.show()

这只会渲染和显示具有两个矩形而不是表情符号的图像

This just renders and image with two rectangles instead of the emoji

非常感谢您的帮助或想法.

Would appreciate any help or ideas.

谢谢!

正如falsetru所指出的那样,该代码确实可以在Ubuntu中运行,但是不能在Windows或Mac上运行.有什么想法吗?

As falsetru pointed out, this code does run in Ubuntu, however it doesn't run on Windows or on Mac. Any ideas?

推荐答案

枕头中有一个错误,请参见#3777 .现在应该使用 PR#3780 在Pillow 6.1版中修复此问题,但是仅适用于Python 3.x.

There was a bug in Pillow, see #1774 or #3777. This should now be fixed in version 6.1 of Pillow with PR#3780, but only for Python 3.x.

这篇关于使用PIL渲染表情符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆