col*_*ain 8 python unicode python-imaging-library emoji
我试图用推文制作图像,但其中一些包含Emojis.我正在使用PIL渲染我的图像和Symbola字体.
文本采用unicode utf-8编码,Symbola字体包含表情符号.这是代码的删节版本:
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()
Run Code Online (Sandbox Code Playgroud)
这只是渲染和图像有两个矩形而不是表情符号
将不胜感激任何帮助或想法.
谢谢!
编辑:正如falsetru所指出的,这段代码确实在Ubuntu中运行,但它不能在Windows或Mac上运行.有任何想法吗?
如果符号 CYCLONE u"\U0001f300" (我从网上下载了一个 Symbola.tff),那么与 PIL 一起使用非常简单:
from PIL import Image, ImageDraw, ImageFont, ImageFilter
#configuration
font_size=36
width=500
height=100
back_ground_color=(255,255,255)
font_size=36
font_color=(0,0,0)
unicode_text =u"\U0001f300"
im = Image.new ( "RGB", (width,height), back_ground_color )
draw = ImageDraw.Draw ( im )
unicode_font = ImageFont.truetype("Symbola.ttf", font_size)
draw.text ( (10,10), unicode_text, font=unicode_font, fill=font_color )
im.show()
Run Code Online (Sandbox Code Playgroud)
看看这个
| 归档时间: |
|
| 查看次数: |
2093 次 |
| 最近记录: |