Insert colorful emoji into an image(Python)

Viewed 1828

I am trying to insert emoji into an image using pillow library but the result is not what I want.

I want the emoji look exactly the same as it looks in iphone, but the result is a black and white ugly emoji.

this is my code:

from PIL import Image, ImageDraw, ImageFont

back_ground_color = (255, 255, 255)
font_color = (0, 0, 0)

unicode_text = u"\U0001f618"
im = Image.new("RGB", (200, 200), back_ground_color)
draw = ImageDraw.Draw(im)
unicode_font = ImageFont.truetype("Symbola.ttf", 36)
draw.text((80, 80), unicode_text, font=unicode_font, fill=font_color)
im.show()

and below is the reult:

enter image description here

So what am i doing wrong?

4 Answers

Add embedded_color=True to your ImageDraw.Draw(image).text so like this:

ImageDraw.Draw(image).text((0, 332), "\U0001F3AC\U0001F44B\U0001F3FB\U0001F44B\U0001F3FF", fill="white", embedded_color=True, font=fnt)

It seems that Symbola is not a color emoji font, you can not show color emoji with it!

You need to try those color emoji fonts, like NotoColorEmoji, AppleColorEmoji or segoeuiemoji. The first two are bit-map color emoji font and the last one is vector color emoji font.

I have tested the three font and they work well for me:

from PIL import Image, ImageDraw, ImageFont

back_ground_color = (255, 255, 255)

unicode_text = "\U0001f602"
im = Image.new("RGB", (500, 500), back_ground_color)
draw = ImageDraw.Draw(im)

# seem only black and white, no color info
# unicode_font = ImageFont.truetype(r"E:\symbola-font\Symbola-AjYx.ttf", 30)

# bit-map based, src: https://github.com/googlefonts/noto-emoji/blob/main/fonts/NotoColorEmoji.ttf
# unicode_font = ImageFont.truetype(r"E:\NotoColorEmoji.ttf", 109)

# bit-map based, src: https://github.com/samuelngs/apple-emoji-linux/releases
unicode_font = ImageFont.truetype(r"E:\AppleColorEmoji.ttf", 137)

# font from here: https://fontsdata.com/132714/segoeuiemoji.htm (for test only)
# svg-based, works with different font size
# unicode_font = ImageFont.truetype(r"E:\segoeuiemoji\seguiemj.ttf", 50)

draw.text((80, 80), unicode_text, font=unicode_font, embedded_color=True)
im.show()

Pillow version: 8.3.2

Ref

https://github.com/python-pillow/Pillow/pull/4955

Related