我希望输出是这样的(在 GitHub 上找到):
.
但目前我是这样的:
表情符号的肤色在我的输出中分离。我该如何解决?我需要其他库吗?
GitHub代码:https ://github.com/python-pillow/Pillow/pull/4955
from PIL import Image, ImageDraw, ImageFont
def test(font, out_name):
fnt = ImageFont.truetype(font, size=109, layout_engine=ImageFont.LAYOUT_RAQM)
im = Image.new("RGBA", (600, 600), (100, 100, 100, 100))
draw = ImageDraw.Draw(im)
draw.text((0, 32), "a\u263A", fill="#faa2", embedded_color=True, font=fnt)
draw.text((0, 132), "a\u263A", fill="#faa8", embedded_color=True, font=fnt)
draw.text((0, 232), "a\u263A", fill="#faa", embedded_color=True, font=fnt)
draw.text((0, 332), "\U0001F3AC\U0001F44B\U0001F3FB\U0001F44B\U0001F3FF", fill="white", embedded_color=True, font=fnt)
draw.text((0, 432), "a\u263A", fill="#faa2", font=fnt)
im.show()
im.save(f"testemoji_{out_name}.png")
test(r"C:\Users\Nulano\Downloads\NotoColorEmoji.ttf", "cbdt")
test("seguiemj.ttf", "colr")
我的代码:
from PIL import Image, ImageDraw, ImageFont
def test(font, out_name):
fnt = ImageFont.truetype(font, size=109, layout_engine=ImageFont.LAYOUT_BASIC,encoding='utf-16')
im = Image.new("RGBA", (800, 600), (100, 100, 100, 0))
draw = ImageDraw.Draw(im)
draw.text((0, 32), "a\u263A",font=fnt, fill="#faa2", embedded_color=True)
draw.text((0, 132), "a\u263A",font=fnt, fill="#faa8", embedded_color=True)
draw.text((0, 232), "a\u263A", fill="#faa",font=fnt, embedded_color=True)
draw.text((0, 332), "\U0001F3AC\U0001F44B\U0001F3FB\U0001F44B\U0001F3FF",font=fnt, fill="white", embedded_color=True)
draw.text((0, 432), "a\u263A",font=fnt, fill="#faa2", embedded_color=True)
im.save(path+"testemoji_{out_name}.png")
return im
# test(path+"Roboto/NotoColorEmoji.ttf", "cbdt")
test(path+"Roboto/seguiemj.ttf", "colr")